public class ShowParameters extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String title = "Reading All Request Parameters";
out.println("<html><head><title>读取参数</title></head>"
+ "<body bgcolor='#FDF5E6'>\n"
+ "<h1 align=center>" + title + "</h1>\n"
+"<table border=1 align=center>\n"
+"<tr bgcolor='#FFAD00'>\n"
+"<th>Parameter Name<th>Parameter Value(s)"
);
Map<String,String[]> map = request.getParameterMap();
for (String key : map.keySet()) {
out.print("<tr><td>" + key + "\n<td>");
if(map.get(key).length == 1){
String paramValue = map.get(key)[0];
if(paramValue.length() == 0)
out.println("<i>No Value</i>");
else
out.println(paramValue);
}else{
out.println("<ul>");
for (int i = 0; i < map.get(key).length; i++){
out.println("<li>" + map.get(key)[i]);
}
out.println("</ul>");
}
}
out.println("</table>\n</body></html>");
}
}