关于 struts的初级问题(修正)
报错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
org.apache.struts.tiles.xmlDefinition.FactorySet.getDefinition(FactorySet.java:156)
org.apache.struts.tiles.definition.ComponentDefinitionsFactoryWrapper.getDefinition(ComponentDefinitionsFactoryWrapper.java:124)
org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:180)
org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:309)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
源文件:
LoginAction.java---------------------------------------
/*
* 创建日期 2007-9-13
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package nwpu.edu.eclipse.struts.action;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import nwpu.edu.eclipse.struts.form.LoginForm;
/**
* @author pk
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class LoginAction extends Action {
private static final long serialVersionUID = 1L;
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
String encoding = request.getCharacterEncoding();
LoginForm actionForm =(LoginForm)form;
String userid = actionForm.getUsername();
String password = actionForm.getPassword();
if(userid.equals( "user ")&&password.equals( "123456 "))
{
return(mapping.findForward( "success "));
}
else
{
return (mapping.findForward( "fail "));
}
}
}
------------------------
struts-config.xml
<?xml version= "1.0 "?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN " "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean name= "loginForm " type= "nwpu.edu.eclipse.struts.form.LoginForm "/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<!-- <action forward= "/eclipse_Struts.jsp " path= "/index ">
</action>
<action forward= "/welcome.jsp " path= "/welcome ">
</action> -->
<action path= "/logincheck "
name= "loginForm "
type= "nwpu.edu.eclipse.struts.action.LoginAction "
scope= "request "
validate= "true ">
<forward name= "success " path= "/eclipse_Struts.jsp "> </forward>
<forward name= "fail " path= "/error.jsp "> </forward>
</action>
</action-mappings>
<controller processorClass= "org.apache.struts.tiles.TilesRequestProcessor "/>
<message-resources parameter= "MessageResources "/>
<plug-in className= "org.apache.struts.tiles.TilesPlugin ">
<set-property property= "moduleAware " value= "true "/>
</plug-in>
<plug-in className= "org.apache.struts.validator.ValidatorPlugIn ">
<set-property property= "pathnames " value= "/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml "/>
</plug-in>
</struts-config>
---------
请大家看看什么原因?谢谢
[解决办法]
你先把以下内容注释掉看看。
<controller processorClass= "org.apache.struts.tiles.TilesRequestProcessor "/>
<plug-in className= "org.apache.struts.tiles.TilesPlugin ">
<set-property property= "moduleAware " value= "true "/>
</plug-in>
可能是你在配置文件里面载入了tiles组件,但是又缺少titles依赖的资源。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html