`

request 参数

阅读更多

 

 

package com.jie.request.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.security.Principal;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;

import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;

import org.hibernate.classic.Session;

import com.jie.request.db.DBhelper;
import com.jie.request.entity.RequestInfoEntity;
import com.jie.request.entity.Test;

/**
 * Servlet implementation class RequestInfoServlet
 */
@WebServlet(
		description = "description", 
		urlPatterns = { "/RequestInfoServlet" }, 
		initParams = { 
				@WebInitParam(name = "initName", value = "initValue", description = "initNameDesc")
		})
public class RequestInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequestInfoServlet() {
        super();
        System.out.println("RequestInfoServlet()");
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		System.out.println("init()");
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		System.out.println("destroy()");
	}

	/**
	 * @see Servlet#getServletConfig()
	 */
	public ServletConfig getServletConfig() {
		System.out.println("getServletConfig()");
		return null;
	}

	/**
	 * @see Servlet#getServletInfo()
	 */
	public String getServletInfo() {
		System.out.println("getServletInfo()");
		return null; 
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
//	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		System.out.println("service()");
//	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		System.out.println("doPost()");
		request.setCharacterEncoding("utf-8");
		RequestInfoEntity r = new RequestInfoEntity();
//		request.authenticate(response);//证明是真实的、可靠的或有效的;鉴定,使生效
		
		AsyncContext asyncContext = request.getAsyncContext();//需要在异步启动之后才能够访问,否则会报异常。
		if(asyncContext!=null)
		{
			r.setAsyncContext(asyncContext.toString());
		}
		System.out.println("asyncContext = " + asyncContext);
		
		Object attribute = request.getAttribute("name");//返回指定属性的对象,或者给定名称的属性存在空值。
		if(attribute!=null)
		{
			r.setAttribute(attribute.toString());
		}
		System.out.println("attribute = " + attribute);
		
		
		request.setAttribute("a", "a");
		request.setAttribute("a", "b");
		request.setAttribute("b", "b");
		request.setAttribute("c", "c");
		Enumeration<String> attributeNames = request.getAttributeNames();//返回一个包含提供给该请求的属性的名称枚举。
		
		System.out.println("attributeNames = " + attributeNames);
		
		StringBuffer attributeNamesDB = new StringBuffer();
		if(attributeNames.hasMoreElements())
		{
			attributeNamesDB.append("["); 
			while (attributeNames.hasMoreElements()) 
			{
				String string = (String) attributeNames.nextElement();
				System.out.print("string = " + string);
				
				attributeNamesDB.append(string);
				attributeNamesDB.append(",");
				
				Object value = request.getAttribute(string);
				System.out.println("  value = " + value);
				
			}
			
			attributeNamesDB.append("]");
			attributeNamesDB.deleteCharAt(attributeNamesDB.length()-2);
			System.out.println("attributeNamesDB = " + attributeNamesDB.toString());
		}
		else
		{
			attributeNamesDB.append("["); 
			attributeNamesDB.append("]");
			System.out.println("attributeNamesDB = " + attributeNamesDB.toString());
		}
		r.setAttributeNames(attributeNamesDB.toString());
		
		String authType = request.getAuthType();//返回用来保护servlet的认证方案的名称。
		r.setAuthType(authType);
		System.out.println("authType = " + authType);
		
		String characterEncoding = request.getCharacterEncoding();//返回此请求的主体中使用的字符编码​​的名称。
		r.setCharacterEncoding(characterEncoding);
		System.out.println("characterEncoding = " + characterEncoding);
		
		Class<? extends HttpServletRequest> class1 = request.getClass();
		r.setClassName(class1.getName().toString());
		System.out.println("class1 = " + class1.getName());
		
		int contentLength = request.getContentLength();//返回请求体的长度,以字节为单位,并通过对输入流提供或-1,如果长度是不知道。
		r.setContentLength(String.valueOf(contentLength));
		System.out.println("contentLength = " + contentLength);
		
		String contentType = request.getContentType();// 如果返回的类型是不知道的MIME类型的请求的主体,或者null。
		r.setContentType(contentType);
		System.out.println("contentType = " + contentType);
		
		String contextPath = request.getContextPath();//返回请求的URI,表示该请求的上下文的一部分。
		r.setContextPath(contextPath);
		System.out.println("contextPath = " + contextPath);
		
		Cookie[] cookies = request.getCookies();//返回一个包含所有的Cookie对象的数组这个请求发送的客户端。
		
		StringBuffer cookiesDB = new StringBuffer();
		
		if(cookies != null && cookies.length >0)
		{
			cookiesDB.append("["); 
			for (int i = 0; i < cookies.length; i++) 
			{
				Cookie cookie = cookies[i];
				
				//cookie 对象
				Object clone = cookie.clone();
				System.out.println("clone = " + clone);
				cookiesDB.append(clone);
				cookiesDB.append(",");
				
				String comment = cookie.getComment();
				System.out.println("comment = " + comment);
				cookiesDB.append(comment);
				cookiesDB.append(",");
				
				String domain = cookie.getDomain();
				System.out.println("domain = " + domain);
				cookiesDB.append(domain);
				cookiesDB.append(",");
				
				int maxAge = cookie.getMaxAge();
				System.out.println("maxAge = " + maxAge);
				cookiesDB.append(maxAge);
				cookiesDB.append(",");
				
				String name = cookie.getName();
				System.out.println("name = " + name);
				cookiesDB.append(name);
				cookiesDB.append(",");
				
				String path = cookie.getPath();
				System.out.println("path = " + path);
				cookiesDB.append(path);
				cookiesDB.append(",");
				
				boolean secure = cookie.getSecure();
				System.out.println("secure = " + secure);
				cookiesDB.append(secure);
				cookiesDB.append(",");
				
				String value = cookie.getValue();
				System.out.println("value = " + value);
				cookiesDB.append(value);
				cookiesDB.append(",");
				
				int version = cookie.getVersion();
				System.out.println("version = " + version);
				cookiesDB.append(version);
				cookiesDB.append(",");
				
				boolean httpOnly = cookie.isHttpOnly();
				System.out.println("httpOnly = " + httpOnly);
				cookiesDB.append(httpOnly);
				cookiesDB.append(",");
				
				cookie.setComment("");
				cookie.setDomain("");
				cookie.setHttpOnly(true);
				cookie.setMaxAge(0);
				cookie.setPath("");
				cookie.setSecure(true);
				cookie.setValue("");
				cookie.setVersion(0);
				
				System.out.println("name = " + name);
				System.out.println("value = " + value);
			}
			cookiesDB.append("]"); 
			cookiesDB.deleteCharAt(cookiesDB.length()-2);
			System.out.println("cookiesDB = " + cookiesDB.toString());
		}
		System.out.println("cookies = " + cookies);
		r.setCookies(cookiesDB.toString());
		
		long dateHeader = request.getDateHeader("name");
		r.setDateHeader(String.valueOf(dateHeader));
		System.out.println("dateHeader = " + dateHeader);
		
		DispatcherType dispatcherType = request.getDispatcherType();
		System.out.println("dispatcherType = " + dispatcherType);
		StringBuffer dispatcherTypeDB = new StringBuffer();
		dispatcherTypeDB.append("[");
		
		String name = dispatcherType.name();
		System.out.println("dispatcherType name = " + name);
		dispatcherTypeDB.append(name);
		dispatcherTypeDB.append(",");
		
		int ordinal = dispatcherType.ordinal();
		System.out.println("dispatcherType ordinal = " + ordinal);
		dispatcherTypeDB.append(ordinal);
		dispatcherTypeDB.append(",");
		
		Class<DispatcherType> declaringClass = dispatcherType.getDeclaringClass();
		System.out.println("dispatcherType declaringClass = " + declaringClass);
		dispatcherTypeDB.append(declaringClass);
		dispatcherTypeDB.append(",");
		
		dispatcherTypeDB.append("]"); 
		
		dispatcherTypeDB.deleteCharAt(dispatcherTypeDB.length()-2);
		System.out.println("dispatcherTypeDB = " + dispatcherTypeDB.toString());
		r.setDispatcherType(dispatcherTypeDB.toString());
		
		//TODO 浏览器
		String header = request.getHeader("User-Agent");
		r.setHeader(header);
		System.out.println("header = " + header);
		
		Enumeration<String> headerNames = request.getHeaderNames();
		StringBuffer headerNamesDB = new StringBuffer();
		headerNamesDB.append("[");
		while (headerNames.hasMoreElements()) 
		{
			String nextElement = (String) headerNames.nextElement();
			headerNamesDB.append(nextElement);
			headerNamesDB.append(",");
			System.out.println("nextElement = " + nextElement);
		}
		headerNamesDB.append("]"); 
		
		headerNamesDB.deleteCharAt(headerNamesDB.length()-2);
		r.setHeaderNames(headerNamesDB.toString());
		System.out.println("headerNamesDB = " + headerNamesDB.toString());
		
		System.out.println("headerNames = " + headerNames);
		
		Enumeration<String> headers = request.getHeaders("name");
		StringBuffer headersDB = new StringBuffer();
		headersDB.append("[");
		while (headers.hasMoreElements()) 
		{
			String nextElement = (String) headers.nextElement();
			headersDB.append(nextElement);
			headersDB.append(",");
			System.out.println("nextElement" + nextElement);
		}
		headersDB.append("]"); 
		
		headersDB.deleteCharAt(headersDB.length()-2);
		r.setHeaders(headersDB.toString());
		System.out.println("headersDB = " + headersDB);
		System.out.println("headers = " + headers);
		
		ServletInputStream inputStream = request.getInputStream();
		r.setInputStream(inputStream.toString());
		System.out.println("inputStream = " + inputStream);
		
//		long skip = inputStream.skip(0);
		
//		inputStream.reset();
		
//		int read = inputStream.read();
		
//		boolean markSupported = inputStream.markSupported();
		
//		int available = inputStream.available();
		
//		inputStream.close();
		
		int intHeader = request.getIntHeader("name");
		r.setIntHeader(String.valueOf(intHeader));
		System.out.println("intHeader = " + intHeader);
		
		String localAddr = request.getLocalAddr();
		r.setLocalAddr(localAddr);
		System.out.println("localAddr = " + localAddr);
		
		
		Locale locale = request.getLocale();
		System.out.println("locale = " + locale);
		
		StringBuffer localeDB = new StringBuffer();
		localeDB.append("[");
		
		Object clone = locale.clone();
		System.out.println("locale clone = " + clone);
		localeDB.append(clone);
		localeDB.append(",");
		
		String country = locale.getCountry();
		System.out.println("locale country = " + country);
		localeDB.append(country);
		localeDB.append(",");
		
		String displayCountry = locale.getDisplayCountry();
		System.out.println("locale displayCountry = " + displayCountry);
		localeDB.append(displayCountry);
		localeDB.append(",");
		
		String displayLanguage = locale.getDisplayLanguage();
		System.out.println("locale coundisplayLanguagetry = " + displayLanguage);
		localeDB.append(displayLanguage);
		localeDB.append(",");
		
		String displayName = locale.getDisplayName();
		System.out.println("locale displayName = " + displayName);
		localeDB.append(displayName);
		localeDB.append(",");
		
		String displayScript = locale.getDisplayScript();
		System.out.println("locale displayScript = " + displayScript);
		localeDB.append(displayScript);
		localeDB.append(",");
		
		String displayVariant = locale.getDisplayVariant();
		System.out.println("locale displayVariant = " + displayVariant);
		localeDB.append(displayVariant);
		localeDB.append(",");
		
		String extension = locale.getExtension('a');
		System.out.println("locale extension = " + extension);
		localeDB.append(extension);
		localeDB.append(",");
		
		Set<Character> extensionKeys = locale.getExtensionKeys();
		System.out.println("locale extensionKeys = " + extensionKeys);
		localeDB.append(extensionKeys);
		localeDB.append(",");
		
		String iso3Country = locale.getISO3Country();
		System.out.println("locale iso3Country = " + iso3Country);
		localeDB.append(iso3Country);
		localeDB.append(",");
		
		String iso3Language = locale.getISO3Language();
		System.out.println("locale iso3Language = " +iso3Language);
		localeDB.append(iso3Language);
		localeDB.append(",");
		
		String language = locale.getLanguage();
		System.out.println("locale language = " + language);
		localeDB.append(language);
		localeDB.append(",");
		
		String script = locale.getScript();
		System.out.println("locale script = " + script);
		localeDB.append(script);
		localeDB.append(",");
		
		Set<String> unicodeLocaleAttributes = locale.getUnicodeLocaleAttributes();
		System.out.println("locale unicodeLocaleAttributes = " + unicodeLocaleAttributes);
		localeDB.append(unicodeLocaleAttributes);
		localeDB.append(",");
		
		Set<String> unicodeLocaleKeys = locale.getUnicodeLocaleKeys();
		System.out.println("locale unicodeLocaleKeys = " + unicodeLocaleKeys);
		localeDB.append(unicodeLocaleKeys);
		localeDB.append(",");
		
		String variant = locale.getVariant();
		System.out.println("locale variant = " + variant);
		localeDB.append(variant);
		localeDB.append(",");
		
		boolean hasExtensions = locale.hasExtensions();
		System.out.println("locale hasExtensions = " + hasExtensions);
		localeDB.append(hasExtensions);
		localeDB.append(",");
		
		int hashCode = locale.hashCode();
		System.out.println("locale hashCode = " + hashCode);
		localeDB.append(hashCode);
		localeDB.append(",");
		
		Locale stripExtensions = locale.stripExtensions();
		System.out.println("locale stripExtensions = " + stripExtensions);
		localeDB.append(stripExtensions);
		localeDB.append(",");
		
		String languageTag = locale.toLanguageTag();
		System.out.println("locale languageTag = " + languageTag);
		localeDB.append(languageTag);
		localeDB.append(",");
		
		String string3 = locale.toString();
		System.out.println("locale string3 = " + string3);
		localeDB.append(string3);
		localeDB.append(",");
		
//		Locale forLanguageTag = Locale.forLanguageTag(null);
//		System.out.println("locale forLanguageTag = " + forLanguageTag);
//		
		Locale[] availableLocales = Locale.getAvailableLocales();
		System.out.println("locale availableLocales = " + availableLocales);
		localeDB.append(availableLocales);
		localeDB.append(",");
		
		Locale default1 = Locale.getDefault();
		System.out.println("locale default1 = " + default1);
		localeDB.append(default1);
		localeDB.append(",");
		
		String[] isoCountries = Locale.getISOCountries();
		System.out.println("locale isoCountries = " + isoCountries);
		localeDB.append(isoCountries);
		localeDB.append(",");
		
		String[] isoLanguages = Locale.getISOLanguages();
		System.out.println("locale isoLanguages = " + isoLanguages);
		localeDB.append(isoLanguages);
		localeDB.append(",");
		
		localeDB.append("]"); 
		
		localeDB.deleteCharAt(localeDB.length()-2);
		r.setLocale(localeDB.toString());
		System.out.println("localeDB = " + localeDB.toString());
		
		
		String localName = request.getLocalName();
		r.setLocalName(localName);
		System.out.println("localName = " + localName);
		
		//TODO
		Enumeration<Locale> locales = request.getLocales();
		while (locales.hasMoreElements()) 
		{
			Locale nextElement = locales.nextElement();
			String country1 = nextElement.getCountry();
			System.out.println("locale country = " + country1);
		}
		r.setLocales(locales.toString());
		System.out.println("locales = " + locales);
		
		int localPort = request.getLocalPort();
		r.setLocalPort(String.valueOf(localPort));
		System.out.println("localPort = " + localPort);
		
		String method = request.getMethod();
		r.setMethod(method);
		System.out.println("method = " + method);
		
		String parameter = request.getParameter("name");
		r.setParameter(parameter);
		System.out.println("parameter = " + parameter);
		
		//TODO
		Map<String, String[]> parameterMap = request.getParameterMap();
		for (Entry<String, String[]> entry : parameterMap.entrySet()) 
		{
			String[] parameter1 = entry.getValue();
			
			System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
			
			for (int i = 0; i < parameter1.length; i++) 
			{
				String string2 = parameter1[i];
				System.out.println("string2 = " + string2);
			}
		}
		r.setParameterMap(parameterMap.toString());
		System.out.println("parameterMap = " + parameterMap);
		
		//TODO
		Enumeration<String> parameterNames = request.getParameterNames();
		while (parameterNames.hasMoreElements()) 
		{
			String string = (String) parameterNames.nextElement();
			System.out.println("string = " + string);
		}
		r.setParameterNames(parameterNames.toString());
		System.out.println("parameterNames = " + parameterNames);
		
		//TODO
		String[] parameterValues = request.getParameterValues("name");
		if(parameterValues != null)
		{
			for (int i = 0; i < parameterValues.length; i++) 
			{
				String string2 = parameterValues[i];
				System.out.println("string2 = " + string2);
			}
		}
		if(parameterValues!=null)
		{
			r.setParameterValues(parameterValues.toString());
		}
		
		System.out.println("parameterValues = " + parameterValues);
		
		Part part = request.getPart("name");
		
		StringBuffer partDB = new StringBuffer();
		partDB.append("[");
		
		if(part != null)
		{
//			part.delete();
			String contentType2 = part.getContentType();
			System.out.println("contentType2 = " + contentType2);
			partDB.append(contentType2);
			partDB.append(",");
			
			String header2 = part.getHeader(null);
			System.out.println("header2 = " + header2);
			partDB.append(header2);
			partDB.append(",");
			
			Collection<String> headerNames2 = part.getHeaderNames();
			System.out.println("headerNames2 = " + headerNames2);
			partDB.append(headerNames2);
			partDB.append(",");
			
			InputStream inputStream2 = part.getInputStream();
			System.out.println("inputStream2 = " + inputStream2);
			partDB.append(inputStream2);
			partDB.append(",");
			
			String name3 = part.getName();
			System.out.println("name3 = " + name3);
			partDB.append(name3);
			partDB.append(",");
			
			long size = part.getSize();
			System.out.println("size = " + size);
			partDB.append(size);
			partDB.append(",");
			
			System.out.println("name3 = " + name3);
		}
		localeDB.append("]"); 
		
		localeDB.deleteCharAt(localeDB.length()-2);
		System.out.println("localeDB = " + localeDB.toString());
		r.setPart(partDB.toString());
		System.out.println("part = " + part);
		
		
		
		
		String pathInfo = request.getPathInfo();
		r.setPathInfo(pathInfo);
		System.out.println("pathInfo = " + pathInfo);
		
		String pathTranslated = request.getPathTranslated();
		r.setPathTranslated(pathTranslated);
		System.out.println("pathTranslated = " + pathTranslated);
		
		String protocol = request.getProtocol();
		r.setProtocol(protocol);
		System.out.println("protocol = " + protocol);
		
		String queryString = request.getQueryString();
		r.setQueryString(queryString);
		System.out.println("queryString = " + queryString);
		
//		BufferedReader reader = request.getReader();
//		String readLine = reader.readLine();
//		System.out.println("readLine = " + readLine);
//		System.out.println("reader = " + reader);
		
		String realPath = request.getRealPath("name");
		r.setRealPath(realPath);
		System.out.println("realPath = " + realPath);
		
		String remoteAddr = request.getRemoteAddr();
		r.setRemoteAddr(remoteAddr);
		System.out.println("remoteAddr = " + remoteAddr);
		
		String remoteHost = request.getRemoteHost();
		r.setRemoteHost(remoteHost);
		//TODO 
		request.setAttribute("ip", remoteHost);
		System.out.println("remoteHost = " + remoteHost);
		
		int remotePort = request.getRemotePort();
		r.setRemotePort(String.valueOf(remotePort));
		System.out.println("remotePort = " + remotePort);
		
		String remoteUser = request.getRemoteUser();
		r.setRemoteUser(remoteUser);
		System.out.println("remoteUser = " + remoteUser);
		
		//TODO
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("name");
//		requestDispatcher.forward(request, response);
//		requestDispatcher.include(request, response);
		
		String name3 = requestDispatcher.getClass().getName();
		System.out.println("name3 = " + name3);
		r.setRequestDispatcher(requestDispatcher.toString());
		System.out.println("requestDispatcher = " + requestDispatcher);
		
		String requestURI = request.getRequestURI();
		r.setRequestURI(requestURI);
		System.out.println("requestURI = " + requestURI);
		
		String requestedSessionId = request.getRequestedSessionId();
		r.setRequestedSessionId(requestedSessionId);
		System.out.println("requestedSessionId = " + requestedSessionId);
		
		StringBuffer requestURL = request.getRequestURL();
		r.setRequestURL(requestURL.toString());
		System.out.println("requestURL = " + requestURL.toString());
		
		String scheme = request.getScheme();
		r.setScheme(scheme);
		System.out.println("scheme = " + scheme);
		
		String serverName = request.getServerName();
		r.setServerName(serverName);
		System.out.println("serverName = " + serverName);
		
		int serverPort = request.getServerPort();
		r.setServerPort(String.valueOf(serverPort));
		System.out.println("serverPort = " + serverPort);
		
		ServletContext servletContext = request.getServletContext();
		r.setServletContext(servletContext.toString());
//		String contextPath2 = servletContext.getContextPath();
//		Enumeration<String> attributeNames2 = servletContext.getAttributeNames();
//		ClassLoader classLoader = servletContext.getClassLoader();
//		String contextPath3 = servletContext.getContextPath();
//		Set<SessionTrackingMode> defaultSessionTrackingModes = servletContext.getDefaultSessionTrackingModes();
//		Map<String, ? extends FilterRegistration> filterRegistrations = servletContext.getFilterRegistrations();
//		Set<SessionTrackingMode> effectiveSessionTrackingModes = servletContext.getEffectiveSessionTrackingModes();
//		int effectiveMajorVersion = servletContext.getEffectiveMajorVersion();
//		
//		System.out.println("contextPath2 = " + contextPath2);
//		System.out.println("servletContext = " + servletContext);
		
		String servletPath = request.getServletPath();
		r.setServletPath(servletPath);
		System.out.println("servletPath = " + servletPath);
		
		//TODO session
		HttpSession session = request.getSession();
		r.setSession(session.toString());
		long creationTime = session.getCreationTime();
		
		
		System.out.println("creationTime = " + creationTime);
		System.out.println("session = " + session);
		
		HttpSession session2 = request.getSession(true);
		System.out.println("session2 = " + session2);
		
		//TODO
		Principal userPrincipal = request.getUserPrincipal();
		if(userPrincipal != null)
		{
			String string = userPrincipal.toString();
			System.out.println("string = " + string);
			
			String name4 = userPrincipal.getName();
			System.out.println("name4 = " + name4);
			System.out.println("userPrincipal = " + userPrincipal);
		}
		if(userPrincipal!=null)
		{
			r.setUserPrincipal(userPrincipal.toString());
		}
		
		boolean asyncStarted = request.isAsyncStarted();
		r.setAsyncStarted(String.valueOf(asyncStarted));
		System.out.println("asyncStarted = " + asyncStarted);
		
		boolean asyncSupported = request.isAsyncSupported();
		r.setAsyncSupported(String.valueOf(asyncSupported));
		System.out.println("asyncSupported = " + asyncSupported);
		
		boolean requestedSessionIdFromCookie = request.isRequestedSessionIdFromCookie();
		r.setRequestedSessionIdFromCookie(String.valueOf(requestedSessionIdFromCookie));
		System.out.println("requestedSessionIdFromCookie = " + requestedSessionIdFromCookie);
		
		boolean requestedSessionIdFromUrl = request.isRequestedSessionIdFromUrl();
		r.setRequestedSessionIdFromUrl(String.valueOf(requestedSessionIdFromUrl));
		System.out.println("requestedSessionIdFromUrl = " + requestedSessionIdFromUrl);
		
		boolean requestedSessionIdFromURL2 = request.isRequestedSessionIdFromURL();
		System.out.println("requestedSessionIdFromURL2 = " + requestedSessionIdFromURL2);
		
		boolean requestedSessionIdValid = request.isRequestedSessionIdValid();
		r.setRequestedSessionIdValid(String.valueOf(requestedSessionIdValid));
		System.out.println("requestedSessionIdValid = " + requestedSessionIdValid);
		
		boolean secure = request.isSecure();
		r.setSecure(String.valueOf(secure));
		System.out.println("secure = " + secure);
		
		boolean userInRole = request.isUserInRole("name");
		r.setUserInRole(String.valueOf(userInRole));
		System.out.println("userInRole = " + userInRole);
		
//		request.login("name", "name2");
//		System.out.println("string = " + string);
		
//		request.logout();
//		System.out.println("string = " + string);
		
		request.removeAttribute("name");
		r.setRemoveAttribute("removeAttribute");
//		System.out.println("string = " + string);
		
		request.setAttribute("name", "name1");
		r.setSetAttribute("setAttribute");
//		System.out.println("string = " + string);
		
		request.setCharacterEncoding("utf-8");
		r.setSetCharacterEncoding("setCharacterEncoding");
//		System.out.println("string = " + string);
		
//		AsyncContext startAsync = request.startAsync();
//		long timeout = startAsync.getTimeout();
//		System.out.println("timeout = " + timeout);
//		System.out.println("startAsync = " + startAsync);
//		
//		AsyncContext startAsync2 = request.startAsync(request, response);
//		long timeout1 = startAsync.getTimeout();
//		System.out.println("timeout1 = " + timeout1);
//		System.out.println("startAsync2 = " + startAsync2);
		
		String basicAuth = request.BASIC_AUTH;
		r.setBasicAuth(basicAuth);
		System.out.println("basicAuth = " + basicAuth);
		
		String clientCertAuth = request.CLIENT_CERT_AUTH;
		r.setClientCertAuth(clientCertAuth);
		System.out.println("clientCertAuth = " + clientCertAuth);
		
		String digestAuth = request.DIGEST_AUTH;
		r.setDigestAuth(digestAuth);
		System.out.println("digestAuth = " + digestAuth);
		
		String formAuth = request.FORM_AUTH;
		r.setFormAuth(formAuth);
		System.out.println("formAuth = " + formAuth);
		
		//TODO 得到浏览器名称和操作系统名称
//		StringTokenizer st = new StringTokenizer(header,";");  
//		st.nextToken(); 
//		if(st.hasMoreTokens())
//		{
//			//得到用户的浏览器名  
//			String userBrowser = st.nextToken();
//			r.setUserBrowser(userBrowser);
//			//得到用户的操作系统名  
//			String userOs = st.nextToken();
//			r.setUserOs(userOs);
//		}
		
		
		String accept = request.getHeader("Accept");
		r.setHeaderAccept(accept);
		System.out.println("accept = " + accept);
		
		String host = request.getHeader("Host");
		r.setHeaderHost(host);
		System.out.println("host = " + host);
		
		String referer = request.getHeader("Referer");
		r.setHeaderReferer(referer);
		System.out.println("referer = " + referer);
		
		
		String Accept_Language = request.getHeader("Accept-Language");
		r.setHeaderAcceptLanguage(Accept_Language);
		System.out.println("Accept-Language = " + Accept_Language);
		
		String Accept_Encoding = request.getHeader("Accept-Encoding");
		r.setHeaderAcceptEncoding(Accept_Encoding);
		System.out.println("Accept-Encoding = " + Accept_Encoding);
		
		String connection = request.getHeader("Connection");
		r.setHeaderConnection(connection);
		System.out.println("connection = " + connection);
		
		String cookie = request.getHeader("Cookie");
		r.setHeaderCookie(cookie);
		System.out.println("cookie = " + cookie);
		
		String Cache_Control = request.getHeader("Cache-Control");
		r.setHeaderCacheControl(Cache_Control);
		System.out.println("Cache_Control = " + Cache_Control);
		
		String server = request.getHeader("Server");
		r.setHeaderServer(server);
		System.out.println("server = " + server);
		
		String Content_Length = request.getHeader("Content-Length");
		r.setHeaderContentLength(Content_Length);
		System.out.println("Content-Length = " + Content_Length);
		
		String Content_Type = request.getHeader("Content-Type");
		r.setHeaderContentType(Content_Type);
		System.out.println("Content-Type = " + Content_Type);
		
		String date = request.getHeader("Date");
		r.setHeaderDate(date);
		System.out.println("date = " + date);
		
		String expires = request.getHeader("Expires");
		r.setHeaderExpires(expires);
		System.out.println("Expires = " + expires);
		
		String Transfer_Encoding = request.getHeader("Transfer-Encoding");
		r.setHeaderTransferEncoding(Transfer_Encoding);
		System.out.println("Transfer-Encoding = " + Transfer_Encoding);
		
		String Vary = request.getHeader("Vary");
		r.setHeaderVary(Vary);
		System.out.println("Vary = " + Vary);
		
		String x_forwarded_for = request.getHeader("x-forwarded-for");
//		r.setHeaderVary(Vary);
		System.out.println("x-forwarded-for = " + x_forwarded_for);
		
		
		
		
		
		
		//hibernate Entity Save
		Session sessionHiber = DBhelper.getSessionFactory().openSession();
		sessionHiber.beginTransaction();
		sessionHiber.save(r);
		sessionHiber.getTransaction().commit();
		sessionHiber.close();
		request.getRequestDispatcher("ok.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPut(HttpServletRequest, HttpServletResponse)
	 */
	protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doPut()");
	}

	/**
	 * @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse)
	 */
	protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doDelete()");
	}

	/**
	 * @see HttpServlet#doHead(HttpServletRequest, HttpServletResponse)
	 */
	protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doHead()");
	}

	/**
	 * @see HttpServlet#doOptions(HttpServletRequest, HttpServletResponse)
	 */
	protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doOptions()");
	}

	/**
	 * @see HttpServlet#doTrace(HttpServletRequest, HttpServletResponse)
	 */
	protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doTrace()");
	}

}

 

分享到:
评论

相关推荐

    使用HttpServletRequestWrapper在filter修改request参数

    标题“使用HttpServletRequestWrapper在filter修改request参数”揭示了主要知识点,即如何在过滤器中通过自定义`HttpServletRequestWrapper` 子类来动态改变请求参数。这通常用于处理如数据验证、安全过滤、参数转换...

    测试Request 参数

    在IT行业中,尤其是在Web开发领域,"测试Request参数"是一个重要的环节。Request对象是ASP.NET Web应用程序中的一个关键组件,它允许我们从客户端(通常是浏览器)接收数据。在这个场景中,我们看到几个与Web应用...

    获取request参数名.txt

    获取request参数名.txt

    flex通过URL获取request参数

    标题中的"flex通过URL获取request参数"指的是在Flex应用程序中解析URL查询字符串以获取用户在请求时传递的参数。例如,给定的URL `http://localhost:8080/text.mxml?myName=good&myValue=goods` 包含两个参数:`my...

    WinForm关于CefSharp获取后的资源、截取request参数、拦截response数据、注入jquery文件和js代码

    接下来,我们讨论如何截取request参数。在`OnBeforeResourceLoad`方法中,你可以通过`request`参数访问到`IRequest`对象,这个对象包含了请求的所有信息,如URL、方法(GET或POST)、请求头等。你可以读取并修改这些...

    WinForm窗体程序中使用CefSharp获取加载后的资源、截取request参数、拦截response数据、注入jquery文件和js代码。

    环境:vs2019、.net 4.6。 WinForm窗体程序中使用CefSharp获取加载后的资源、截取request参数、拦截response数据、注入jquery文件和js代码。有问题可联系q369628105

    java web 修改request携带的参数信息

    Request对象封装了客户端发送到服务器的所有数据,包括URL参数、请求头、请求体等。在某些场景下,可能需要对这些参数信息进行修改,比如安全过滤、数据校验或者日志记录等。本程序就是针对这种情况设计的一个实用...

    Request中的参数转实体类

    主要用于使用Request中的getParamterMap()方法生成一个实体类,其中还包括getParamterMap中字段的检查方法。详见内容!

    filter对request请求拦截,对请求参数进行修改

    对request请求进行拦截,对请求参数修改。常用于前台提交表单参数关键字的过滤。此工具可以对参数拦截并转义后提交到对应的处理类。 除了添加两个JsFilter.java和GetHttpServletRequestWrapper.java之外,需要在web....

    Symfony实现行为和模板中取得request参数的方法

    首先,让我们看如何在模板中获取request参数。在Symfony模板中,你可以使用`$sf_request`全局变量来访问当前的请求对象。以下是一些示例: 1. 获取名为`name`的参数,如果没有提供默认值则返回空字符串: ```php ...

    C# request获取参数.docx

    C# Request 获取参数详解 在 C# 中,获取请求参数是 Web 开发中一个非常重要的步骤。Request 对象提供了多种方式来获取请求参数,本文将详细介绍 Request.Params、Request、Request.QueryString、Request.Form 和 ...

    ASP.NET Core自定义中间件如何读取Request.Body与Response.Body的内容详解

    本文将深入探讨如何在自定义中间件中读取`Request.Body`和`Response.Body`的内容。 首先,`Request.Body`代表HTTP请求的主体部分,通常用于发送POST数据或文件上传。它是`Stream`类型的,可以读取请求的数据。在ASP...

    java遍历http请求request的所有参数实现方法

    本篇文章将详细介绍如何使用Java遍历HTTP请求request的所有参数,并将其存储到HashMap中。 首先,我们需要导入相关的Java Servlet库,这通常在Servlet环境如Tomcat或Jetty中运行。导入以下依赖: ```java import ...

    使用JavaScript获取Request中参数的值方法

    这篇文章将详细讲解如何使用JavaScript和jQuery来获取URL请求(Request)中的参数值。 首先,我们需要理解URL的结构。URL通常由协议、主机名、端口号(可选)、路径和查询字符串组成。在查询字符串中,参数以键值对...

    request获取url以及其参数

    当你需要从客户端(通常是浏览器)获取URL及其参数时,`HttpServletRequest`扮演了核心角色。本篇文章将详细探讨如何使用`HttpServletRequest`来获取URL和参数。 首先,让我们理解URL(Uniform Resource Locator)...

    获取request的参数

    本篇将深入探讨如何在不同的编程语言和框架中获取`request`的参数,以实现有效的数据交互。 首先,我们来看一下`request`对象。在HTTP请求中,`request`对象是服务器端用来接收和处理客户端请求的关键组件。它包含...

    09_Java Web——Request&Response案例

    在"Demo1"这个示例中,很可能包含了实现上述概念的代码片段,例如一个简单的Servlet处理HTTP请求,读取Request参数,写入Response响应,或者使用MyBatis进行数据库操作。通过分析和运行这些代码,你可以更深入地理解...

    jsp参数传递

    - 获取request参数: ```jsp Object paramvalue = request.getAttribute("paramname"); ``` #### 五、多页面间参数传递 在多页面间传递参数通常涉及到多个步骤,这时可以利用session对象来存储中间结果。例如,...

    python requests包的request()函数中的参数-params和data的区别介绍

    在`requests`包的`request()`函数中,有两个关键参数`params`和`data`,它们在不同的场景下有不同的用途。 1. `params` 参数: `params` 用于发送查询字符串(query string)到URL中。当你需要向一个URL传递额外的...

Global site tag (gtag.js) - Google Analytics