当前位置: 代码迷 >> Java Web开发 >> 求助:关于struts
  详细解决方案

求助:关于struts

热度:267   发布时间:2007-08-27 15:25:35.0
求助:关于struts

本人是初学者,现在用struts写的web程序,编译正常,但是当我按提交按钮处理数据的时候,却出错:
2007-8-23 23:17:48 org.apache.struts.chain.commands.AbstractExceptionHandler exe
cute
警告: Unhandled exception
java.lang.NullPointerException
at ulj.system.baokan.entryAction.execute(entryAction.java:37)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(Execut
eAction.java:53)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(Abstra
ctExecuteAction.java:64)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionComm
andBase.java:48)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.
java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(Composable
RequestProcessor.java:280)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:185
8)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Unknown Source)
2007-8-23 23:17:48 org.apache.struts.chain.commands.ExceptionCatcher postprocess

警告: Exception from exceptionCommand 'servlet-exception'
java.lang.NullPointerException
at ulj.system.baokan.entryAction.execute(entryAction.java:37)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(Execut
eAction.java:53)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(Abstra
ctExecuteAction.java:64)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionComm
andBase.java:48)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.
java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(Composable
RequestProcessor.java:280)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:185
8)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Unknown Source)
出错页面原码如下:
package ulj.system.baokan;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import ulj.system.baokan.User;

public class entryAction extends Action {
//创建对数据操作连接
DataBaseModel dao = new DataBaseModel();
// public entryAction() {
// System.out.println("income action");
// }
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
System.out.println("income action");
//从web层获得用户名和口令
User userForm = (User) form;
System.out.println("userForm.user==");
String userName = userForm.getUser_name().trim();
String userPass = userForm.getUser_pass().trim();
System.out.println("userName========="+userName);
//声明错误集对象
ActionErrors errors = new ActionErrors();
//校验输入
if((userName.equals(""))||(userName.equals(null)))
{
//未登录用户,重定向到注册页面
request.getSession().setAttribute("error","用户未登录!");
return new ActionForward("/error.jsp");
}
if(dao.isValid(userName,userPass))
{
request.getSession().setAttribute("UserName", userName);
return mapping.findForward("main");
}
else
{
request.getSession().setAttribute("error","错误的用户名或密码!");
return new ActionForward("error");
}
// String url = (String) request.getParameter("url");
// System.out.println("url:"+url);
// return mapping.findForward(url);
}

}

搜索更多相关主题的帖子: struts  

----------------解决方案--------------------------------------------------------
return new ActionForward("/error.jsp"); // ActionForward中参数你可以去api,有重载的!是对应actio-mapping中的forward参数!必需在struts-config中配置!
----------------解决方案--------------------------------------------------------
回复:(uljhao)求助:关于struts

报的错误的地方是不能通过: String userName = userForm.getUser_name().trim()这种方式取form中的值.
就这个点出的错,想知道这个错误是由什么引起的呢?

[此贴子已经被作者于2007-8-27 18:24:55编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案