Friday, January 15, 2016

HttpServletRequest

Functions

  1. getRequestURL //full URL in type of StringBuffer: "http://localhost:8080/webapp/servlet1"
  2. getRequestURI //full URL in type of String: "/webapp/servlet1"
  3. getQueryString //all parameters string "name=abc&email=abc@gvace.com"
  4. getRemoteAddr //client IP address
  5. getRemoteHost //client host name if is registered in DNS server, return IP if not registered
  6. getRemotePort //client connection port
  7. getLocalPort //return server port "8080"
  8. getLocalAddr //web server IP address
  9. getLocalName //web server name
  10. getHeader("Host") //
  11. getHeaders() //return Enumeration
  12. getHeaderNames() //return Enumeration
  13. getParameter()
  14. getParameterValues(String name) // return String[], return null if no input
  15. getParameterNames()
Request Forward
  • request.getRequestDispatcher("/servlet1").forward(request,response);
    //forward to another servlet within webapp, share the same request and response
    //forward url can be only within the same webapp, so no "webapp" directory needed
    //keeping the same URL in browser
    //different from response.sendRedirect("/webapp/servlet1"); using different request/response
    //after the getRequestDispatcher("/servlet1").forward(request,response), all code continues to run, so make sure to return and finish the service

No comments:

Post a Comment