ParametersValue
d 4
b 2
c 3
a 1

PrtReqParas.java

 

01.import java.io.PrintWriter;
02.import java.io.IOException;
03.import java.util.Enumeration;
04.import javax.servlet.annotation.WebServlet;
05. 
06.import javax.servlet.ServletException;
07.import javax.servlet.http.HttpServlet;
08.import javax.servlet.http.HttpServletRequest;
09.import javax.servlet.http.HttpServletResponse;
10. 
11.@WebServlet(name = "printParas", urlPatterns = {"/printParas/"}, loadOnStartup = 1)
12.public class PrtReqParas extends HttpServlet {
13. 
14.@Override
15.public void doGet(HttpServletRequest request, HttpServletResponse response)
16.throws IOException, ServletException {
17. 
18.printParas(request, response);
19.}
20. 
21.@Override
22.public void doPost(HttpServletRequest request, HttpServletResponse response)
23.throws IOException, ServletException {
24. 
25.printParas(request, response);
26.}
27. 
28. 
29.public void printParas(HttpServletRequest request, HttpServletResponse response)
30.throws IOException, ServletException {
31. 
32.response.setContentType("text/html");
33. 
34.PrintWriter out = response.getWriter();
35.out.println("<!doctype html>");
36.out.println("<html><head><title>Request Parameters</title></head>");
37.out.println("<body>");
38.out.println("<table align=center border=1>");
39.out.println("<tr><th>Parameters</th><th>Value</th></tr>");
40. 
41. 
42.String para = null;
43.Enumeration<String> e = request.getParameterNames();
44.while(e.hasMoreElements()) {
45.para = e.nextElement();
46.if(para != null){
47.out.println("<tr><td align=center>" + para + "</td>");
48.out.println("<td align=center>" + request.getParameter(para) + "</td></tr>");
49.}
50.}
51. 
52.out.println("</table>");
53.out.println("</body></html>");
54.}
55.}
創作者介紹

資訊園

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()