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


Java ServletResponse.setCharacterEncoding方法代码示例

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


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

示例1: onPreHandle

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
    if (this.isAccessAllowed(request, response, mappedValue) && this.isLoginRequest(request, response)) {
        if (((HttpServletRequest)request).getRequestURL().toString().endsWith(".json")){
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json; charset=utf-8");
            PrintWriter out = response.getWriter();
            out.println("{\"code\":200,\"info\":\"already logined\"}");
            out.flush();
            out.close();
        }else {
            WebUtils.issueRedirect(request,response,this.getSuccessUrl());
        }
        return false;
    }
    return super.onPreHandle(request, response, mappedValue);
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:18,代码来源:LoginFilter.java

示例2: writeJson

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
/**
 * response 输出JSON
 * @param response
 * @param resultMap
 * @throws IOException
 */
public static void writeJson(ServletResponse response, Map<String, Object> resultMap){
	PrintWriter out = null;
	try {
		response.setCharacterEncoding("UTF-8");
		out = response.getWriter();
		out.print(JSON.toJSONString(resultMap));
	} catch (Exception e) {
		logger.error("输出JSON异常:", e);
	}finally{
		if(null != out){
			out.flush();
			out.close();
		}
	}
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:22,代码来源:ShiroUtils.java

示例3: redirectToLogin

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
protected void redirectToLogin(ServletRequest req, ServletResponse res) throws IOException {
    HttpServletRequest request = (HttpServletRequest) req;

    if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
        res.setContentType("text/xml");
        res.setCharacterEncoding("UTF-8");

        String loginUrl = getLoginUrl();
        if (loginUrl.startsWith("/") || !loginUrl.startsWith("http")) {
            // If it is a relative URL, use the context path.
            loginUrl = request.getContextPath() + loginUrl;
        }
        res.getWriter().printf(FACES_REDIRECT_XML, loginUrl);
    } else {
        super.redirectToLogin(req, res);
    }
}
 
开发者ID:atbashEE,项目名称:atbash-octopus,代码行数:19,代码来源:UserFilter.java

示例4: onAccessDenied

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    if (isLoginRequest(request, response)) {
        if (isLoginSubmission(request, response)) {
            if (log.isTraceEnabled()) {
                log.trace("Login submission detected.  Attempting to execute login.");
            }
            return executeLogin(request, response);
        } else {
            if (log.isTraceEnabled()) {
                log.trace("Login page view.");
            }
            // allow them to see the login page ;)
            return true;
        }
    } else {
        if (log.isTraceEnabled()) {
            log.trace("Attempting to access a path which requires authentication.  Forwarding to the "
                    + "Authentication url [" + getLoginUrl() + "]");
        }
        if (!((HttpServletRequest)request).getRequestURL().toString().endsWith(".json")) {
            saveRequestAndRedirectToLogin(request, response);
        } else {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json; charset=utf-8");
            PrintWriter out = response.getWriter();
            out.println("{\"code\":-203,\"info\":\"login\"}");
            out.flush();
            out.close();
        }
        return false;
    }
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:34,代码来源:LoginFilter.java

示例5: onLoginFailure

import javax.servlet.ServletResponse; //导入方法依赖的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

示例6: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的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

示例7: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    HttpSession session = req.getSession(false);
    String loginURI = req.getContextPath() + "/login";

    boolean loggedIn = session != null && session.getAttribute("user") != null;
    boolean loginRequest = req.getRequestURI().equals(loginURI);
    boolean resourceRequest = req.getRequestURI().startsWith(req.getContextPath() + RESOURCE_IDENTIFIER + "/");
    boolean ajaxRequest = "partial/ajax".equals(req.getHeader("Faces-Request"));

    if (loggedIn || loginRequest || resourceRequest) {
        if (!resourceRequest) {
            res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            res.setHeader("Pragma", "no-cache");
            res.setDateHeader("Expires", 0);
        }
        chain.doFilter(new AuthRequestWrapper((HttpServletRequest) request), response);
    } else if (ajaxRequest) {
        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().printf(AJAX_REDIRECT_XML, loginURI);
    } else {
        res.sendRedirect(loginURI);
    }
}
 
开发者ID:nickscha,项目名称:servlet-auth,代码行数:28,代码来源:AuthRequestFilter.java

示例8: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的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

示例9: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的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

示例10: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的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


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