Request中的方法调用
几种方法的调用:
package com.stono.servlet; import java.io.IOException; import java.util.Enumeration; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class TestServlet2 extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("do get method called!"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String method = req.getMethod(); System.out.println("method is " + method); Enumeration<String> headerNames = req.getHeaderNames(); int i = 0; while (headerNames.hasMoreElements()) { String nextElement = headerNames.nextElement(); String header = req.getHeader(nextElement); System.out.println(++i + ":" + nextElement + ":" + header); } System.out.println("===============COOKIE================"); Cookie[] cookies = req.getCookies(); for (Cookie cookie : cookies) { System.out.println(cookie); cookie.getName(); cookie.getValue(); cookie.getVersion(); } System.out.println("================Remote==================="); String remoteAddr = req.getRemoteAddr(); String remoteHost = req.getRemoteHost(); int remotePort = req.getRemotePort(); String remoteUser = req.getRemoteUser(); System.out.println(remoteAddr); System.out.println(remoteHost); System.out.println(remotePort); System.out.println(remoteUser); System.out.println("================Server==================="); String serverName = req.getServerName(); int serverPort = req.getServerPort(); String servletPath = req.getServletPath(); System.out.println(serverName); System.out.println(serverPort); System.out.println(servletPath); System.out.println("================Local==================="); String localAddr = req.getLocalAddr(); String localName = req.getLocalName(); int localPort = req.getLocalPort(); System.out.println(localAddr); System.out.println(localName); System.out.println(localPort); System.out.println("do post method called"); String[] strings = req.getParameterValues("txt1"); System.out.println(strings.length); for (String string : strings) { System.out.println(string); } } }