我有一组三个 servlet,每个都有一个带有单选按钮的表单,这些单选按钮将其值传递给下一个 servlet。我要做的是制作一个 JavaBean 类来与 servlet 一起使用,并在从一个 servlet 到另一个 servlet 时保持它们的状态和单选按钮的选择。任何人都可以建议一些JavaBean的示例代码吗?
这是一些第一个 servlet 代码:
(其他两个 servlet 对其他问题有相同的代码)
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet 1</title>");
out.println("</head>");
out.println("<form id=\"form1\" action = \"Servlet2\" method = \"POST\">");
out.println("<input type = \"radio\" name = \"Q1\" value = \"Answer 1\"> Answer 1 <br />\n" +
"<input type = \"radio\" name = \"Q1\" value = \"Answer 2\"> Answer 2 <br />\n" +
"<input type = \"radio\" name = \"Q1\" value = \"Answer 3\"> Answer 3 <br /> <br />");
out.println("<input type = \"radio\" name = \"Q2\" value = \"Answer 1\"> Answer 1 <br />\n" +
"<input type = \"radio\" name = \"Q2\" value = \"Answer 2\"> Answer 2 <br />\n" +
"<input type = \"radio\" name = \"Q2\" value = \"Answer 3\"> Answer 3 <br /> <br />");
out.println("<input type = \"radio\" name = \"Q3\" value = \"Answer 1\"> Answer 1 <br />\n" +
"<input type = \"radio\" name = \"Q3\" value = \"Answer 2\"> Answer 2 <br />\n" +
"<input type = \"radio\" name = \"Q3\" value = \"Answer 3\"> Answer 3 <br /> <br />");
out.println("<input type = \"submit\" value = \"Next\">");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
谢谢你。