eclipseを使ってjavaの勉強を行っています。
DB情報の入ったリスト(A)を別のリスト(B)に入れたいです。
リスト(B)は最初だけ初期化したいのでinit()の中に記載しようと考えていいます。
init()の中に本などで調べながら配列を宣言はしたのですが、これも合っているかわかりません。
リストを作成したのですが、その後のリスト(A)をリスト(B)に入れていくやり方がわかりません。DB情報は一度sessionにセットしているため値はsessionから取り出せばいいでしょうか?
お力をお借りしたいです。
public void init(ServletConfig config) throws ServletException { super.init(config); List<Product> addlist = new ArrayList<>(); ServletContext application= config.getServletContext(); application.setAttribute("addlist" , addlist); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("product_inf"); int quantity = Integer.parseInt(request.getParameter("quantity")); SalesSearchDAO dao = new SalesSearchDAO(); List<Product> saleslist = (dao.search(quantity , code)); HttpSession session = request.getSession(); session.setAttribute("saleslist", saleslist); RequestDispatcher rd = request.getRequestDispatcher("./sales.jsp"); rd.forward(request, response);
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/06 07:44