Root cause of ServletException.
weblogic.utils.ParsingException: nested TokenStreamException: antlr.TokenStreamIOException
at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java(Compiled Code))
at weblogic.servlet.jsp.JspParser.doit(JspParser.java:106)
at weblogic.servlet.jsp.JspParser.parse(JspParser.java:234)
at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:125)
at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:258)
at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:388)
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:238)
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:188)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java(Compiled Code))
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java(Compiled Code))
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java(Compiled Code))
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:322)
at edu.yale.its.tp.cas.servlet.Login.doGet(Login.java:188)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java(Inlined Compiled Code))
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java(Compiled Code))
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java(Inlined Compiled Code))
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java(Compiled Code))
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java(Compiled Code))
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java(Inlined Compiled Code))
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java(Compiled Code))
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java(Compiled Code))
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java(Compiled Code))
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
>
原因:中文编码问题
解决:在web.xml里加上过滤:
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>edu.yale.its.tp.cas.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
--------------//SetCharacterEncodingFilter类是中文过滤类
package edu.yale.its.tp.cas;
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;
/**
* Example filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding.
* 如果原来没有设置request的编码,就设置;否则保持不变
*/
public class SetCharacterEncodingFilter
implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
/**
* Take this filter out of service.
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*/
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); //设置request编码的地方
}else
{
request.setCharacterEncoding("gb2312"); //强制设置编码
}
}
// Pass control on to the next filter
// 传递控制到下一个过滤器
chain.doFilter(request, response);
}
/**
* Place this filter into service.
* 从web-app的web.xml文件中读取初始参数的值
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null) {
this.ignore = true;
}
else if (value.equalsIgnoreCase("true")) {
this.ignore = true;
}
else if (value.equalsIgnoreCase("yes")) {
this.ignore = true;
}
else {
this.ignore = false;
}
}
/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* 选择request原来的编码
*/
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}