Servlet-得到路径

//获得当前url
  StringBuffer url = new StringBuffer(request.getScheme() + "://" + request.getServerName()
    + request.getRequestURI());
//判断当前url是否有参数
  if(request.getQueryString()!=null && !"".equals(request.getQueryString())){
         url.append("?" + request.getQueryString());
  }

一些信息返回:


HttpSession session=request.getSession();
		out.println("</br>rotocol: " + request.getProtocol()); 
		out.println("</br>Scheme: " + request.getScheme()); 
		out.println("</br>Server Name: " + request.getServerName() ); 
		out.println("</br>Server Port: " + request.getServerPort()); 
		out.println("</br>rotocol: " + request.getProtocol()); 
		out.println("</br>Server Info: " + getServletConfig().getServletContext().getServerInfo()); 
		out.println("</br>Remote Addr: " + request.getRemoteAddr()); 
		out.println("</br>Remote Host: " + request.getRemoteHost()); 
		out.println("</br>Character Encoding: " + request.getCharacterEncoding()); 
		out.println("</br>Content Length: " + request.getContentLength()); 
		out.println("</br>Content Type: "+ request.getContentType()); 
		out.println("</br>Auth Type: " + request.getAuthType()); 
		out.println("</br>HTTP Method: " + request.getMethod()); 
		out.println("</br>path Info: " + request.getPathInfo()); 
		out.println("</br>path Trans: " + request.getPathTranslated()); 
		out.println("</br>Query String: " + request.getQueryString()); 
		out.println("</br>Remote User: " + request.getRemoteUser()); 
		out.println("</br>Session Id: " + request.getRequestedSessionId()); 
		out.println("</br>Request URI: " + request.getRequestURI()); 
		out.println("</br>Servlet Path: " + request.getServletPath()); 
		out.println("</br>Accept: " + request.getHeader("Accept")); 
		out.println("</br>Host: " + request.getHeader("Host")); 
		out.println("</br>Referer : " + request.getHeader("Referer")); 
		out.println("</br>Accept-Language : " + request.getHeader("Accept-Language")); 
		out.println("</br>Accept-Encoding : " + request.getHeader("Accept-Encoding")); 
		out.println("</br>User-Agent : " + request.getHeader("User-Agent")); 
		out.println("</br>Connection : " + request.getHeader("Connection")); 
		out.println("</br>Cookie : " + request.getHeader("Cookie")); 
		out.println("</br>Created : " + session.getCreationTime()); 
		out.println("</br>LastAccessed : " + session.getLastAccessedTime());
//结果
rotocol: HTTP/1.1 
Scheme: http 
Server Name: 219.243.90.145 
Server Port: 8080 
rotocol: HTTP/1.1 
Server Info: Apache Tomcat/7.0.42 
Remote Addr: 219.243.90.133 
Remote Host: 219.243.90.133 
Character Encoding: null 
Content Length: -1 
Content Type: null 
Auth Type: null 
HTTP Method: GET 
path Info: null 
path Trans: null 
Query String: null 
Remote User: null 
Session Id: DB96F2252D3B9CF3317B126F752583A6 
Request URI: /ServletContext/SContext 
Servlet Path: /SContext 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Host: 219.243.90.145:8080 
Referer : null 
Accept-Language : zh-CN,zh;q=0.8 
Accept-Encoding : gzip,deflate,sdch 
User-Agent : Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1 
Connection : keep-alive 
Cookie : JSESSIONID=DB96F2252D3B9CF3317B126F752583A6 
Created : 1380787989521 
LastAccessed : 1380788046278

你可能感兴趣的:(Servlet-得到路径)