问题描述
- 关于tomcat 报错原因
-
description The server encountered an internal error () that prevented it from fulfilling this request.exception
java.lang.ClassCastException: com.sany.web.session.WebSession cannot be cast to java.lang.String
com.sany.web.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:34)》<!--->note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
/**
- */
package com.sany.web.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;import com.sany.util.log.ILogger;
public class SetCharacterEncodingFilter implements Filter {
private static final ILogger logger = ILogger.getInstance().getILogger(SetCharacterEncodingFilter.class);
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub} public void doFilter(ServletRequest request, ServletResponse response, FilterChain fileter) throws IOException, ServletException { // TODO Auto-generated method stub request.setCharacterEncoding("GBK"); HttpServletRequest req = (HttpServletRequest) request;
// response.setCharacterEncoding("GBK");
try{
fileter.doFilter(request, response);}
catch(Exception e){
logger.error((String)req.getSession().getAttribute("user"),"doFilter(ServletRequest request=" + request
+ ", ServletResponse response=" + response
+ ") - [方法错误]", e);e.printStackTrace(); } } public void destroy() { // TODO Auto-generated method stub }
}
- */
解决方案
com.sany.web.session.WebSession cannot be cast to java.lang.String
类型转换错误 应该用WebSession接的你用的是String
错误在etCharacterEncodingFilter.java:34
解决方案二:
(String)(req.getSession().getAttribute("user"))