当前位置: 首页>>代码示例>>Java>>正文


Java ServletRequest类代码示例

本文整理汇总了Java中javax.servlet.ServletRequest的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest类的具体用法?Java ServletRequest怎么用?Java ServletRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ServletRequest类属于javax.servlet包,在下文中一共展示了ServletRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
    throws IOException, ServletException {
  final HttpServletRequest request = (HttpServletRequest) req;

  final String authHeader = request.getHeader("Authorization");
  if (authHeader == null || !authHeader.startsWith("Bearer ")) {
    ExceptionUtils.createUnauthorizedException("Missing or invalid Authorization header.", res);
    return;
  }

  try {
    final String token = authHeader.substring(7); // The part after "Bearer "
    final Claims claims =
        Jwts.parser().setSigningKey("secretkey").parseClaimsJws(token).getBody();
    request.setAttribute("claims", claims);
  } catch (final Exception e) {
    ExceptionUtils.createUnauthorizedException("Invalid token", res);
    return;
  }

  chain.doFilter(req, res);
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:24,代码来源:JwtFilter.java

示例2: setRequest

import javax.servlet.ServletRequest; //导入依赖的package包/类
/**
 * Set the request that we are wrapping.
 *
 * @param request The new wrapped request
 */
@Override
public void setRequest(ServletRequest request) {

    super.setRequest(request);

    // Initialize the attributes for this request
    synchronized (attributes) {
        attributes.clear();
        Enumeration<String> names = request.getAttributeNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            Object value = request.getAttribute(name);
            attributes.put(name, value);
        }
    }

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:ApplicationRequest.java

示例3: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    out.print(getClass().getName());
    chain.doFilter(request, response);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:TestStandardContext.java

示例4: send401

import javax.servlet.ServletRequest; //导入依赖的package包/类
private void send401(ServletRequest httpRequest,
        HttpServletResponse httpResponse, HttpSession session, boolean asTM) {
    // Return 401 error
    String clientLocale = httpRequest.getLocale().getLanguage();
    if (clientLocale.equals(LOCALE_JA)) {
        clientLocale = LOCALE_DEFAULT;
    }
    httpResponse.setHeader(
            "WWW-Authenticate",
            "Basic realm=\""
                    + Messages.get(clientLocale,
                            (asTM ? "ui.config.authentication.tm"
                                    : "ui.config.authentication.appadmin"))
                    + "\"");
    httpResponse.setStatus(401);
    session.invalidate();

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:AuthorizationFilter.java

示例5: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException {

  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  String servletPath = req.getServletPath() + req.getPathInfo();
  xLogger.fine("Servlet path: ", servletPath);
  if (req.getCharacterEncoding() == null) {
    request.setCharacterEncoding(Constants.UTF8);
  }

  if (!(StringUtils.isNotBlank(servletPath) && servletPath.startsWith(MEDIA_ENDPOINT_URL))) {
    resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    return;
  }
  if (filterChain != null) {
    filterChain.doFilter(request, response);
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:MediaSecurityFilter.java

示例6: onLoginFailure

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
    if (!((HttpServletRequest)request).getRequestURL().toString().endsWith(".json")) {
        setFailureAttribute(request, e);
        return true;
    }
    try {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = response.getWriter();
        String message = e.getClass().getSimpleName();
        if ("IncorrectCredentialsException".equals(message)
                || "UnknownAccountException".equals(message)
                ) {
            out.println("{\"code\":-100010,\"info\":\"账号或密码错误\"}");
        }else if("ExcessiveAttemptsException".equals(message)){
            out.println("{\"code\":-100020,\"info\":\"密码错误次数超过限制,请10分钟后重试!\"}");
        }else if("LockedAccountException".equals(message)){
            out.println("{\"code\":-100030,\"info\":\"账号已停用!\"}");
        } else {
            out.println("{\"code\":-100500,\"info\":\"未知错误\"}");
        }
        out.flush();
        out.close();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return false;
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:31,代码来源:LoginFilter.java

示例7: dispatch

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
public void dispatch(ServletRequest request, ServletResponse response) throws ServletException, IOException {
	if (Globals.IS_SECURITY_ENABLED) {
		try {
			PrivilegedDispatch dp = new PrivilegedDispatch(request, response);
			AccessController.doPrivileged(dp);
		} catch (PrivilegedActionException pe) {
			Exception e = pe.getException();

			if (e instanceof ServletException)
				throw (ServletException) e;
			throw (IOException) e;
		}
	} else {
		doDispatch(request, response);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:18,代码来源:ApplicationDispatcher.java

示例8: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
/**
   * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
   *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
   */
  public void doFilter( ServletRequest request, 
          			  ServletResponse response,
          			  FilterChain chain ) throws IOException, ServletException {
      
      // Get Filter Init Parameters
      String replaceStrParam = filterConfig.getInitParameter("replace_string");
      String addlCharsParam = filterConfig.getInitParameter("additional_chars");
      
      // Set variables
      if(replaceStrParam!=null)
          replaceStr = replaceStrParam;
      if(addlCharsParam!=null)
          addlChars = addlCharsParam;
      
      // Construct allowed characters pattern
      String charPattern = "([^" + charsAllowed + addlChars + "]+)(%0A)";        
      
      // Instantiate actual filter
      RequestXSSFilter rxs = new RequestXSSFilter( 
              (HttpServletRequest) request, replaceStr, charPattern);

// Process request
chain.doFilter(rxs,response);

  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:30,代码来源:XSSFilter.java

示例9: setRequest

import javax.servlet.ServletRequest; //导入依赖的package包/类
/**
 * Set the request that we are wrapping.
 *
 * @param request The new wrapped request
 */
public void setRequest(ServletRequest request) {

    super.setRequest(request);

    // Initialize the attributes for this request
    synchronized (attributes) {
        attributes.clear();
        Enumeration names = request.getAttributeNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            Object value = request.getAttribute(name);
            attributes.put(name, value);
        }
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:ApplicationRequest.java

示例10: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
/**这个方法完成实际的过滤操作。当客户请求访问与过滤器关联的URL的时候,Servlet过滤器将先执行doFilter方法。FilterChain参数用于访问后续过滤器。*/
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		
		//忽略不过滤页面
		if(!Statics.ignore_login_page.contains(httpRequest.getServletPath())){
			long memberId = StorageUtil.init(httpRequest.getSession()).getLoginMemberId();
			if(memberId==ReturnUtil.NOT_LOGIN_CODE){
				String url = httpRequest.getScheme()+"://"+httpRequest.getServerName()+":"+httpRequest.getServerPort()+httpRequest.getContextPath();
				DataUtil.OutStreamByResponse(httpResponse, "<script type='text/javascript'>top.location.href= '"+url+Statics.Login_Page+"';</script>");
				return;
			}
		}
		chain.doFilter(request, response);
//		httpRequest.getScheme();//协议类型			http
//		httpRequest.getServerName();//域名		mycdsxlc.f3322.net
//		httpRequest.getServerPort();//端口号		8989
//		httpRequest.getContextPath();//项目名		/Report
//		httpRequest.getServletPath();//请求页面	/web/index.jsp
//		httpRequest.getQueryString();//参数		null
	}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:23,代码来源:PageFilter.java

示例11: service

import javax.servlet.ServletRequest; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @throws ApplicationContextException if the DispatcherServlet does not
 * initialize properly, but the servlet attempts to process a request.
 */
@Override
public void service(final ServletRequest req, final ServletResponse resp)
    throws ServletException, IOException {
    /*
     * Since our container calls only this method and not any of the other
     * HttpServlet runtime methods, such as doDelete(), etc., delegating
     * this method is sufficient to delegate all of the methods in the
     * HttpServlet API.
     */
    if (this.initSuccess) {
        this.delegate.service(req, resp);
    } else {
        throw new ApplicationContextException("Unable to initialize application context.");
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:21,代码来源:SafeDispatcherServlet.java

示例12: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
/**
    * Time the processing that is performed by all subsequent filters in the
    * current filter stack, including the ultimately invoked servlet.
    *
    * @param request The servlet request we are processing
    * @param result The servlet response we are creating
    * @param chain The filter chain we are processing
    *
    * @exception IOException if an input/output error occurs
    * @exception ServletException if a servlet error occurs
    */
   public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain)
throws IOException, ServletException {

// Store ourselves as a request attribute (if requested)
if (attribute != null)
    request.setAttribute(attribute, this);

// Time and log the subsequent processing
long startTime = System.currentTimeMillis();
       chain.doFilter(request, response);
long stopTime = System.currentTimeMillis();
filterConfig.getServletContext().log
    (this.toString() + ": " + (stopTime - startTime) +
     " milliseconds");

   }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:ExampleFilter.java

示例13: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    HttpSession session = request.getSession(false);

    if (session == null || session.getAttribute("LoggedUser") == null) {
        response.sendRedirect(request.getContextPath() + "/index.jsp"); // No logged-in user found, so redirect to login page.
    } else {
    	DynUser currentUser = (DynUser) session.getAttribute("LoggedUser");
    	if (!currentUser.isAdmin()) {
    		response.sendRedirect(request.getContextPath() + "/app/dashboard.jsp"); // No admin user found, so redirect to dashboard page.
    	} else {        	
    		chain.doFilter(req, res); // Logged-in user found, so just continue request.
    	}
    }
}
 
开发者ID:CanadianRepublican,项目名称:DDNS_Server,代码行数:17,代码来源:AdminFilter.java

示例14: invoke

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
public void invoke(Request request, Response response, ValveContext valveContext) throws IOException, ServletException {
    valveContext.invokeNext(request, response);

    System.out.println("Header Logger Valve:");
    ServletRequest sreq = request.getRequest();
    if(sreq instanceof HttpServletRequest){
        HttpServletRequest hreq = (HttpServletRequest) sreq;
        Enumeration<String> headerNames = hreq.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String headerName = headerNames.nextElement().toString();
            String headerValue = hreq.getHeader(headerName);
            System.out.println(headerName + ": " + headerValue);
        }
    }else {
        System.out.println("Not an HTTP Request");
    }
    System.out.println("-------------------------------------");
}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:20,代码来源:HeaderLoggerValve.java

示例15: doFilter

import javax.servlet.ServletRequest; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest req0, ServletResponse resp0,
        FilterChain chain) throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req0;
    HttpServletResponse response = (HttpServletResponse) resp0;

    String authorization = request.getHeader("Authorization");
    if (authorization != null) {
        String c[] = parseAuthorization(authorization);
        if (c != null && credentials.containsKey(c[0])
                && credentials.get(c[0]).equals(c[1])) {
            chain.doFilter(request, response);
            return;
        }
    }

    response.setHeader("WWW-Authenticate", "Basic realm=\"Restricted\"");
    response.sendError(401);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:21,代码来源:HTTPBasicAuth.java


注:本文中的javax.servlet.ServletRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。