/**
* 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();
}
Java,遍历Request参数
最新推荐文章于 2022-08-22 10:11:27 发布