struts1.0 报错org.apache.struts.chain.commands.AbstractExceptionHandler execute

2011-5-22 11:39:13 org.apache.struts.chain.ComposableRequestProcessor init

信息: Initializing composable request processor for module prefix ''

2011-5-22 11:39:13 org.apache.struts.chain.commands.AbstractExceptionHandler execute

警告: Unhandled exception

java.lang.NullPointerException

at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)

at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:357)

at org.apache.struts.chain.commands.CreateActionForm.execute(CreateActionForm.java:92)

at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)

at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)

at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Unknown Source)

2011-5-22 11:39:13 org.apache.struts.chain.commands.ExceptionCatcher postprocess

警告: Exception from exceptionCommand 'servlet-exception'

java.lang.NullPointerException

at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)

at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:357)

at org.apache.struts.chain.commands.CreateActionForm.execute(CreateActionForm.java:92)

at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)

at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)

at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Unknown Source)

2011-5-22 11:39:13 org.apache.catalina.core.StandardWrapperValve invoke

严重: Servlet.service() for servlet action threw exception

java.lang.NullPointerException

at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)

at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:357)

at org.apache.struts.chain.commands.CreateActionForm.execute(CreateActionForm.java:92)

at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)

at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)

at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)

at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Unknown Source)

Form如下:

package com.web.form;

import org.apache.struts.action.ActionForm;

public class LoginForm extends ActionForm{

private String userName=null;

private String userPwd=null;

public String getUserName() {

return userName;

}

public void setUserName(String userName) {

this.userName = userName;

}

public String getUserPwd() {

return userPwd;

}

public void setUserPwd(String userPwd) {

this.userPwd = userPwd;

}

}

LoginAction如下:

package com.web.action;

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 com.web.form.LoginForm;

public class LoginAction extends Action{

@Override

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

String userName=request.getParameter("userName");

System.out.println(userName);

LoginForm login=(LoginForm)form;

System.out.println("进入");

if(login.getUserName().equals("tfq")){

return mapping.findForward("loginSuccess");

}else{

return mapping.findForward("loginFailure");

}

}

}

登录jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>My JSP 'login.jsp' starting page</title>

</head>

<body>

<center>

<form action="<%=request.getContextPath()%>/login.do" method="post">

userName:<input type="text" name="userName"/><br />

userPwd:<input type="password" name="userPwd"/><br />

<input type="submit" value="登录" />

<input type="reset" value="重围" />

</form>

</center>

</body>

</html>

web.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- 引入struts1 -->

<servlet>

<servlet-name>action</servlet-name>

<!-- 引入Servlet的包所有的路径 -->

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

<!-- 初始化配置文件 -->

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/struts-config.xml</param-value>

</init-param>

<!-- 当项目一启动就实例化servlet -->

<load-on-startup>0</load-on-startup>

</servlet>

<!-- 对外提供服务 -->

<servlet-mapping>

<servlet-name>action</servlet-name>

<!-- 对所有的请求过滤 -->

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>login.jsp</welcome-file>

</welcome-file-list>

</web-app>

在弄struts1.0时,做了一个简单的登录例子.在做这个例子的时候,报了以上的错.究其因是:

struts-config.xml出问题:

<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE struts-config PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

<!--注册一个Form -->

<form-beans>

<form-bean name="loginForm" type="com.web.LoginForm"></form-bean>

</form-beans>

<action-mappings>

<!-- path:jsp页面访问的action type:指action类路径 name:要引用的Form对象 -->

<action path="/login" type="com.web.action.LoginAction" name="loginForm">

<!-- 成功或失败跳转到相应页面 -->

<forward name="loginSuccess" path="/loginSuccess.jsp"></forward>

<forward name="loginFailure" path="/loginFailure.jsp"></forward>

</action>

</action-mappings>

</struts-config>

我的loginForm的路径本应type="com.web.action.LoginForm" 而我就却写成了com.web.LoginForm

下次得注意这种细节性的问题了。

你可能感兴趣的:(java,apache,Web,struts,servlet)