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


Java ServletRequest.setCharacterEncoding方法代码示例

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


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

示例1: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * 字符集过滤,所有请求都会通过这个过滤
 */
public void doFilter(ServletRequest servletrequest,
		ServletResponse servletresponse, FilterChain filterchain)
		throws IOException, ServletException {
	servletrequest.setCharacterEncoding(targetEncoding);
	try {
		filterchain.doFilter(servletrequest, servletresponse);
	} catch (Exception exception) {
		throw new ServletException(exception);
	} catch (Throwable throwable) {
		throw new ServletException(throwable);
	}
}
 
开发者ID:fellyvon,项目名称:wasexport,代码行数:16,代码来源:EncodingFilter.java

示例2: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * Select and set (if specified) the character encoding to be used to
 * interpret request parameters for this request.
 *
 * @param request The servlet request we are processing
 * @param response 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
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain)
    throws IOException, ServletException {

    // Conditionally select and set the character encoding to be used
    if (ignore || (request.getCharacterEncoding() == null)) {
        String characterEncoding = selectEncoding(request);
        if (characterEncoding != null) {
            request.setCharacterEncoding(characterEncoding);
        }
    }

    // Pass control on to the next filter
    chain.doFilter(request, response);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:28,代码来源:SetCharacterEncodingFilter.java

示例3: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
    * Select and set (if specified) the character encoding to be used to
    * interpret request parameters for this request.
    *
    * @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 {

       // Conditionally select and set the character encoding to be used
       if (ignore || (request.getCharacterEncoding() == null)) {
           String encoding = selectEncoding(request);
           if (encoding != null)
               request.setCharacterEncoding(encoding);
       }

// Pass control on to the next filter
       chain.doFilter(request, response);

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

示例4: 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

示例5: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {
	request.setCharacterEncoding(defaultEncoding);
	response.setCharacterEncoding(defaultEncoding);
	chain.doFilter(request, response);
}
 
开发者ID:NymphWeb,项目名称:nymph,代码行数:8,代码来源:EncodingFilter.java

示例6: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain filterChain) throws IOException, ServletException {
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=utf-8");
	filterChain.doFilter(request, response);
}
 
开发者ID:gingerjiang,项目名称:easycms,代码行数:8,代码来源:CharsetEncodingFilter.java

示例7: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain filterChain) throws IOException, ServletException {
	if(encoding!=null){
		request.setCharacterEncoding(encoding);
		response.setCharacterEncoding(encoding);
	}
	filterChain.doFilter(request, response);
}
 
开发者ID:nihaopl18,项目名称:eaypay,代码行数:10,代码来源:CharacterEncodingFilter.java

示例8: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException 
{
	HttpServletRequest req = (HttpServletRequest)request;
	HttpServletResponse res = (HttpServletResponse)response;
	HttpSession sess = req.getSession();
	String noLoginPaths = config.getInitParameter("noLoginPaths");  
	String path = req.getServletPath();	
	String charset = config.getInitParameter("charset");  
       if(charset==null){  
           charset = "UTF-8";  
       }  
       request.setCharacterEncoding(charset);  
       if(noLoginPaths!=null)
       {  
           String[] strArray = noLoginPaths.split(";");
           for (int i = 0; i < strArray.length; i++)
           {  
               if(strArray[i]==null || "".equals(strArray[i]))
               	continue;  
               if(req.getRequestURI().indexOf(strArray[i])!=-1){  
                   chain.doFilter(request, response);  
                   return;  
               }  
           }  
       }  
	if(sess==null||sess.getAttribute("user_id")==null)
	{
		req.getRequestDispatcher("error.jsp").forward(req, res);
		return;
	}
	else
	{
		chain.doFilter(request, response);
	}
}
 
开发者ID:yanhanwen,项目名称:DrugStoreManagement,代码行数:36,代码来源:UserFilter.java

示例9: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
	request.setCharacterEncoding("UTF-8");
	chain.doFilter(request, response);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:6,代码来源:CharacterEncodingFilter.java

示例10: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
    request.setCharacterEncoding("UTF-8");
    chain.doFilter(request, response);
}
 
开发者ID:alibaba,项目名称:Dragonfly,代码行数:7,代码来源:EncodingFilter.java

示例11: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException {
  xLogger.fine("Entered doFilter");
  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  String servletPath = req.getServletPath();
  if (req.getCharacterEncoding() == null) {
    request.setCharacterEncoding(Constants.UTF8);
  }
  // BACKWARD COMPATIBILITY - in case people have already bookmarked these links
  if ("/index.jsp".equals(servletPath) || "/login.jsp".equals(servletPath)) {
    resp.sendRedirect(isForceNewUI ? HOME_URL_NEW : HOME_URL);
    return;
  }
  SecureUserDetails
      userDetails = null;
  // END BACKWARD COMPATIBILITY
  if (!LOGIN_URL.equals(servletPath) && !AUTHENTICATE_URL.equals(servletPath) && (
      servletPath.isEmpty() || servletPath.equals("/") || servletPath.startsWith("/s/") || (
          servletPath.startsWith(TASK_URL) && StringUtils
              .isBlank(req.getHeader(Constants.X_APP_ENGINE_TASK_NAME))))) {
    userDetails = SecurityMgr
        .getSessionDetails(req.getSession());
    if (userDetails == null) { // session not authenticated yet; direct to login screen
      if (!(servletPath.startsWith(TASK_ADMIN_URL) && ACTION_UPDATESYSCONFIG
          .equals(request.getParameter(ACTION)))) {
        if (isForceNewUI) {
          resp.sendRedirect(HOME_URL_NEW);  // login please
        } else {
          String redirectPath = LOGIN_URL;
          if (servletPath.startsWith("/s/") || servletPath.startsWith(TASK_URL)) {
            String rUrl = servletPath;
            String queryString = req.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
              rUrl += "?" + queryString;
            }
            redirectPath += "?rurl=" + URLEncoder.encode(rUrl, "UTF-8");
          }
          resp.sendRedirect(redirectPath);  // login please
        }
        return;
      }
    } else {
      String role = userDetails.getRole();
      if (SecurityConstants.ROLE_KIOSKOWNER
          .equals(role)) { // Kiosk owner cannot access this interface
        SessionMgr.cleanupSession(req.getSession());
        resp.sendRedirect(LOGIN_URL + "?status=4");
        return;
      }
      if ((servletPath.contains("/admin/") || servletPath.startsWith(TASK_URL))
          && !SecurityConstants.ROLE_SUPERUSER.equals(role)) { // only superuser can access
        SessionMgr.cleanupSession(req.getSession());
        resp.sendRedirect(LOGIN_URL + "?status=4"); // access denied
        return;
      }

    }
  }
  if (userDetails != null) {
    SecurityUtils.setUserDetails(userDetails);
  }
  try {
    if (filterChain != null) {
      filterChain.doFilter(request, response);
    }
  } finally {
    if (userDetails != null) {
      SecurityUtils.setUserDetails(null);
    }
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:74,代码来源:SecurityFilter.java

示例12: 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.isNotEmpty(req.getHeader("app-name"))) {
    filterChain.doFilter(request, response);
  }
  try {
    //this is meant for internal api client
    if (StringUtils.isNotBlank(req.getHeader(X_ACCESS_USER))) {
      try {
        SecurityMgr.setSessionDetails(req.getHeader(X_ACCESS_USER));
      } catch (Exception e) {
        xLogger.severe("Issue with api client authentication", e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        return;
      }

    } else if (StringUtils.isBlank(req.getHeader(Constants.X_APP_ENGINE_TASK_NAME)) && !(
        StringUtils.isNotBlank(servletPath) && (servletPath.startsWith(ASSET_STATUS_URL)
            || servletPath.startsWith(SMS_API_URL) || servletPath.startsWith(M_AUTH_URL)))) {
      String recvdCookie = getAppCookie(req);
      if (appVerAvailable && recvdCookie != null && !appVersion.equals(recvdCookie)) {
        resp.setHeader(ERROR_HEADER_NAME, UPGRADE_REQUIRED_RESPONSE_CODE);
        resp.sendError(HttpServletResponse.SC_CONFLICT, "Upgrade required");
        return;
      }
      if (StringUtils.isNotBlank(servletPath) && !(servletPath.startsWith(APP_STATUS_URL)
          || servletPath.startsWith(AUTHENTICATE_URL))) {
        SecureUserDetails
            userDetails = SecurityMgr
            .getSessionDetails(req.getSession());
        if (userDetails == null) {
          resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Required.");
          return;
        }
        SecurityUtils.setUserDetails(userDetails);
        String reqDomainId = SecurityUtils.getReqCookieUserDomain(req);
        if (reqDomainId != null && !reqDomainId.equals(
            userDetails.getUsername() + CharacterConstants.COLON + SecurityUtils
                .getCurrentDomainId())) {
          resp.setHeader(ERROR_HEADER_NAME, DOMAIN_CHANGE_RESPONSE_CODE);
          resp.sendError(HttpServletResponse.SC_CONFLICT, "Invalid session on client");
          return;
        }
      }

    }

    if (filterChain != null) {
      filterChain.doFilter(request, response);
    }
  } finally {
    SecurityUtils.setUserDetails(null);
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:65,代码来源:APISecurityFilter.java

示例13: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, 
  FilterChain chain) throws IOException, ServletException {
    request.setCharacterEncoding("UTF-8");
    chain.doFilter(request, response);
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:7,代码来源:EncodingFilter.java

示例14: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
	req.setCharacterEncoding(iEncoding);
	resp.setCharacterEncoding(iEncoding);
	chain.doFilter(req, resp);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:9,代码来源:EncodingFilter.java

示例15: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * Select and set (if specified) the character encoding to be used to
 * interpret request parameters for this request.
 *
 * @param request
 *            The servlet request we are processing
 * @param response
 *            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
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {

	// Conditionally select and set the character encoding to be used
	if (ignore || (request.getCharacterEncoding() == null)) {
		String characterEncoding = selectEncoding(request);
		if (characterEncoding != null) {
			request.setCharacterEncoding(characterEncoding);
		}
	}

	// Pass control on to the next filter
	chain.doFilter(request, response);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:32,代码来源:SetCharacterEncodingFilter.java


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