| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 965 人关注过本帖
标题:求助:关于struts
只看楼主 加入收藏
uljhao
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-15
收藏
 问题点数:0 回复次数:2 
求助:关于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 
2007-08-27 15:25
神经塔
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1987
专家分:4
注 册:2006-7-1
收藏
得分:0 
return new ActionForward("/error.jsp"); // ActionForward中参数你可以去api,有重载的!是对应actio-mapping中的forward参数!必需在struts-config中配置!

[shadow=255,red,2]待到秋来九月八,我花开时百花杀。冲天香阵透长安,满城尽是黄金甲。 [/shadow]
2007-08-27 16:42
uljhao
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-15
收藏
得分:0 
回复:(uljhao)求助:关于struts

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

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


既然选择了远方,便只顾风雨兼程.
2007-08-27 18:23
快速回复:求助:关于struts
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017797 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved