回答編集履歴
1
変更後のコードを記載
test
CHANGED
@@ -1 +1,30 @@
|
|
1
1
|
解決いたしました。ありがとうございます。
|
2
|
+
```
|
3
|
+
|
4
|
+
public void init(ServletConfig config) throws ServletException {
|
5
|
+
super.init(config);
|
6
|
+
List<Product> addlist = new ArrayList<>();
|
7
|
+
ServletContext application = config.getServletContext();
|
8
|
+
application.setAttribute("addlist" , addlist);
|
9
|
+
|
10
|
+
}
|
11
|
+
|
12
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
13
|
+
throws ServletException, IOException {
|
14
|
+
|
15
|
+
|
16
|
+
String code = request.getParameter("product_inf");
|
17
|
+
int quantity = Integer.parseInt(request.getParameter("quantity"));
|
18
|
+
SalesSearchDAO dao = new SalesSearchDAO();
|
19
|
+
ServletContext application = this.getServletContext();
|
20
|
+
List<Product> addlist = (List<Product>)application.getAttribute("addlist");
|
21
|
+
|
22
|
+
addlist.addAll(dao.search(quantity , code));
|
23
|
+
|
24
|
+
RequestDispatcher rd = request.getRequestDispatcher("./sales.jsp");
|
25
|
+
rd.forward(request, response);
|
26
|
+
```
|
27
|
+
|
28
|
+
init()中に新しいリストを作成し、そのリストの中にaddAllでDBで取得した内容を入れました。
|
29
|
+
init()の中で宣言しているため初期化は最初の1回だけ行われるのでリストに中に情報がたまっていく形になっています。
|
30
|
+
|