Java代码获取:
import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/site") public class SiteController { @Autowired private HttpServletRequest request; @RequestMapping(value = "/{input:.+}", method = RequestMethod.GET) public ModelAndView getDomain(@PathVariable("input") String input) { ModelAndView modelandView = new ModelAndView("result"); modelandView.addObject("user-agent", getUserAgent()); modelandView.addObject("headers", getHeadersInfo()); return modelandView; } //get user agent private String getUserAgent() { return request.getHeader("user-agent"); } //get request headers private Map<String, String> getHeadersInfo() { Map<String, String> map = new HashMap<String, String>(); Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String key = (String) headerNames.nextElement(); String value = request.getHeader(key); map.put(key, value); } return map; } }
JSP代码获取:
<%! private HttpServletRequest request; private HttpServletResponse response; %> <% System.out.println("Protocol: " + request.getProtocol() + "<br>"); System.out.println("Scheme: " + request.getScheme() + "<br>"); System.out.println("Server Name: " + request.getServerName() + "<br>"); System.out.println("Server Port: " + request.getServerPort() + "<br>"); System.out.println("Protocol: " + request.getProtocol() + "<br>"); System.out.println("Remote Addr: " + request.getRemoteAddr() + "<br>"); System.out.println("Remote Host: " + request.getRemoteHost() + "<br>"); System.out.println("Character Encoding: " + request.getCharacterEncoding() + "<br>"); System.out.println("Content Length: " + request.getContentLength() + "<br>"); System.out.println("Content Type: " + request.getContentType() + "<br>"); System.out.println("Auth Type: " + request.getAuthType() + "<br>"); System.out.println("HTTP Method: " + request.getMethod() + "<br>"); System.out.println("Path Info: " + request.getPathInfo() + "<br>"); System.out.println("Path Trans: " + request.getPathTranslated() + "<br>"); System.out.println("Query String: " + request.getQueryString() + "<br>"); System.out.println("Remote User: " + request.getRemoteUser() + "<br>"); System.out.println("Session Id: " + request.getRequestedSessionId() + "<br>"); System.out.println("Request URL: " + request.getRequestURL() + "<br>"); System.out.println("Request URI: " + request.getRequestURI() + "<br>"); System.out.println("Servlet Path: " + request.getServletPath() + "<br>"); System.out.println("Created : " + session.getCreationTime() + "<br>"); System.out.println("LastAccessed : " + session.getLastAccessedTime() + "<br>"); System.out.println("Accept: " + request.getHeader("Accept") + "<br>"); System.out.println("Host: " + request.getHeader("Host") + "<br>"); System.out.println("Referer : " + request.getHeader("Referer") + "<br>"); System.out.println("Accept-Language : " + request.getHeader("Accept-Language") + "<br>"); System.out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding") + "<br>"); System.out.println("User-Agent : " + request.getHeader("User-Agent") + "<br>"); System.out.println("Connection : " + request.getHeader("Connection") + "<br>"); System.out.println("Cookie : " + request.getHeader("Cookie") + "<br>"); %>