本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}