struts问题高人指点
java.lang.ClassCastException: org.apache.struts.tiles.TilesUtilImpl
org.apache.struts.tiles.TilesRequestProcessor.initDefinitionsMapping(TilesRequestProcessor.java:126)
org.apache.struts.tiles.TilesRequestProcessor.init(TilesRequestProcessor.java:116)
StudentHostle.MyActionServlet.getRequestProcessor(MyActionServlet.java:19)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
StudentHostle.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:28)
web.xml中配置:
<servlet-name> action </servlet-name>
<servlet-class> StudentHostle.MyActionServlet </servlet-class>
<init-param>
<param-name> config </param-name>
<param-value> /WEB-INF/struts-config.xml </param-value>
</init-param>
<init-param>
<param-name> debug </param-name>
<param-value> 2 </param-value>
</init-param>
<load-on-startup> 2 </load-on-startup>
</servlet>
代码:
import org.apache.struts.action.*;
import org.apache.struts.config.*;
import javax.servlet.*;
import org.apache.struts.util.*;
public class MyActionServlet extends ActionServlet {
private static final long serialVersionUID = 1L;
protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config) throws ServletException {
String key = "org.apache.struts.action.REQUEST_PROCESSOR " + config.getPrefix();
RequestProcessor processor = (RequestProcessor)getServletContext().getAttribute(key);
if (processor == null) {
try {
processor = (RequestProcessor) RequestUtils.applicationInstance( "StudentHostle.MyRequestProcessor ");
} catch (Exception e) {
throw new UnavailableException( "Cannot initialize RequestProcessor of class " + config.getControllerConfig().getProcessorClass() + ": " + e);
}
processor.init(this, config);//说我这一行有错
getServletContext().setAttribute(key, processor);
}
return (processor);
}
}
在线等
[解决办法]
是tiles的问题
[解决办法]
代码第10行,定义和初始化processor时,可能得到Null。
代码第17行,调用processor.init(this, config)方法可能会出现类型转换异常java.lang.ClassCastException
[解决办法]
processor = (RequestProcessor) RequestUtils.applicationInstance( "StudentHostle.MyRequestProcessor ");
执行发生了异常,processor就会是null,
所以
processor !=null
processor.init(this, config)前应该加上非空处理