java servlet HttpServletRequest參數


String scheme = req.getScheme();             // http
String serverName = req.getServerName();     // hostname.com
int serverPort = req.getServerPort();        // 80
String contextPath = req.getContextPath();   // /mywebapp
String servletPath = req.getServletPath();   // /servlet/MyServlet
String pathInfo = req.getPathInfo();         // /a/b/c
String queryString = req.getQueryString();   // d=parameter

req.getServletContext().getRealPath(""))
disk path: /home/ubuntu/...
 
req.getServletContext().getRealPath("/WEB-INF/abc.properties"))
disk path: /home/ubuntu/.../WEB-INF/abc.properties
 
request.getServletPath= /test
request.getRequestDispatcher= null
request.getDispatcherType= REQUEST
request.getServletContext().getContextPath()= /project
request.getServletContext().getServletContextName()= Spring MVC Application
request.getServletContext().getContext= null
request.getServletContext().getServletNames()= java.util.Collections$3@b96f4cb 

reference
HttpServletRequest to complete URL
http://stackoverflow.com/questions/2222238/httpservletrequest-to-complete-url 
 
Differents ways to get Servlet Context
http://stackoverflow.com/questions/35837285/differents-ways-to-get-servlet-context 
 
What's the difference between getRequestURI and getPathInfo methods in HttpServletRequest? 
http://stackoverflow.com/questions/4931323/whats-the-difference-between-getrequesturi-and-getpathinfo-methods-in-httpservl 


留言

這個網誌中的熱門文章

Java Servlet MVC web app

JavaMail透過Gmail寄信發生AuthenticationFailedException錯誤