Java,遍历Request参数

来源:互联网 发布:富二代体验知乎 编辑:程序博客网 时间:2024/05/29 11:04
/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. *  * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {Enumeration<String> paramNames = request.getParameterNames();  response.setCharacterEncoding("UTF-8");request.setCharacterEncoding("UTF-8");response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>Get Request Value</TITLE></HEAD>");out.println("  <BODY>");while(paramNames.hasMoreElements()){String paramName = (String)paramNames.nextElement();out.print(paramName + "=");String[] paramValues = request.getParameterValues(paramName);if(paramValues.length == 1){String paramValue = paramValues[0];if(paramValue.length() != 0){out.print(paramValue);}}out.print("<br/>");}out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}

0 0