Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.22 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why isn't this JSP - Servlet code work?
  2. public class x{
  3. private int a;
  4. private int b;
  5. private String c;
  6. private String d;
  7. private String e;
  8. private String f;
  9. //And the fields are encapsulated.
  10. }
  11.        
  12. public class y{
  13. private List<x> xs;
  14. private int k1;
  15. private int k2;
  16. private String k3;
  17. private String k4;
  18. //And the fields are encapsulated.
  19. }
  20.        
  21. <%
  22. usecase y = new y();
  23. request.getSession().setAttribute("yy", y);
  24. %>
  25. <form action="aaa?id=1" method="POST">
  26.             <td>
  27.             <input type="text" name="bbb"/>
  28.             </td>
  29.             <td>
  30.             <input type="text" name="ccc"/>
  31.             </td>
  32.             <td>
  33.             <input type="submit" name="ddd"/>
  34.             </td>
  35.         </form>
  36.        
  37. PrintWriter out = response.getWriter();
  38.     try {
  39.         y yy = (y) request.getSession().getAttribute("yy");
  40.         String id = request.getParameter("id");
  41.         x s = new x();
  42.         s.setC(request.getParameter("bbb"));
  43.         b.setD(request.getParameter("ccc"));
  44.  
  45.         if ("1".equals(id)) {
  46.             s.setE("l");
  47.         } else if ("2".equals(id)) {
  48.             s.setE("k");
  49.         }
  50.  
  51.         yy.getXs().add(s);
  52.         response.sendRedirect("z.jsp");
  53.     } finally {
  54.         out.close();
  55.     }
  56.        
  57. yy.getXs().add(s);