01_6_SERVLET如何从上一个页面取得参数
1. sevlet实现
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//处理从客户端获取的参数 此方法只针对客户端post方法
//request.setCharacterEncoding("utf-8");
//获取客户端传过来的参数
String parameter1 = null;
String parameter2 = null;
String parameter3 = null;
parameter1 = request.getParameter("parameter1");
parameter2 = request.getParameter("parameter2");
parameter3 = request.getParameter("parameter3");
parameter1 = new String(parameter1.getBytes("iso-8859-1"), "utf-8");
parameter2 = new String(parameter2.getBytes("iso-8859-1"), "utf-8");
parameter3 = new String(parameter3.getBytes("iso-8859-1"), "utf-8");
//处理与何种格式回复客户端
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print("TreeParameter Servlet类");
out.print("<br/>");
out.print("第一个参数为:");
out.println(parameter1);
out.print("<br/>");
out.print("第二个参数为:");
out.println(parameter2);
out.print("<br/>");
out.print("第三个参数为:");
out.println(parameter3);
out.print("<br/>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}