异常如下
———————————————————————————————————————
description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
com.action.DeleteLineAction.execute(DeleteLineAction.java:15)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
———————————————————————————————————————
DeleteLineAction.java 如下:package com.action;import com.dao.LineDAO;
import com.opensymphony.xwork2.ActionSupport;
import com.service.ActionManager;public class DeleteLineAction extends ActionSupport {
private static final long serialVersionUID = 1L;
protected ActionManager mgr;
private LineDAO lineDAO;
private Integer lineId;
public String execute() throws Exception{
System.out.println(1);
Integer temp = mgr.validDeleteLine(lineId);
if(temp!=null){
lineDAO.delete(lineId);
System.out.println(lineId);
return "deleteline_success";
}
else{
addActionError("路线不存在");
return "deleteline_failed";
} }
public void setMgr(ActionManager mgr) {
this.mgr = mgr;
} public void setLineDAO(LineDAO lineDAO) {
this.lineDAO = lineDAO;
}
public Integer getLineId() {
return lineId;
} public void setLineId(Integer lineId) {
this.lineId = lineId;
}}
————————————————————————————————————————
DeleteLineAction.java 中的mgr和lineDAO,在spring配置文件里都已经注入,lineId由jsp页面注入,想不通哪个变量能为空。
applicationContext.xml 如下:
<bean name="DeleteLine" class="com.action.DeleteLineAction">
<property name="mgr" ref="mgr"></property>
</bean>
————————————————————————————————————————
struts.xml 如下:
<action name="deleteLine" class="DeleteLine">
<result name="deleteline_failed">/lines.jsp</result>
<result name="deleteline_success">/test.jsp</result>
</action>
————————————————————————————————————————
lines.jsp 如下:
<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><s:text name="行车路线管理" /></title>
</head>
<body>
<div align="center">
<h1><font color=blue><s:text name="行车路线管理" /></font></h1>
<h2><font color=red><s:text name="删除路线"/></font></h2>
<s:form name="deleteLine" action="deleteLine">
<s:textfield name="lineId" key="lid"/>
<br>
<s:submit key="submit"/>
</s:form>
</div>
</body>
</html>
———————————————————————————————————————
description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
com.action.DeleteLineAction.execute(DeleteLineAction.java:15)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
———————————————————————————————————————
DeleteLineAction.java 如下:package com.action;import com.dao.LineDAO;
import com.opensymphony.xwork2.ActionSupport;
import com.service.ActionManager;public class DeleteLineAction extends ActionSupport {
private static final long serialVersionUID = 1L;
protected ActionManager mgr;
private LineDAO lineDAO;
private Integer lineId;
public String execute() throws Exception{
System.out.println(1);
Integer temp = mgr.validDeleteLine(lineId);
if(temp!=null){
lineDAO.delete(lineId);
System.out.println(lineId);
return "deleteline_success";
}
else{
addActionError("路线不存在");
return "deleteline_failed";
} }
public void setMgr(ActionManager mgr) {
this.mgr = mgr;
} public void setLineDAO(LineDAO lineDAO) {
this.lineDAO = lineDAO;
}
public Integer getLineId() {
return lineId;
} public void setLineId(Integer lineId) {
this.lineId = lineId;
}}
————————————————————————————————————————
DeleteLineAction.java 中的mgr和lineDAO,在spring配置文件里都已经注入,lineId由jsp页面注入,想不通哪个变量能为空。
applicationContext.xml 如下:
<bean name="DeleteLine" class="com.action.DeleteLineAction">
<property name="mgr" ref="mgr"></property>
</bean>
————————————————————————————————————————
struts.xml 如下:
<action name="deleteLine" class="DeleteLine">
<result name="deleteline_failed">/lines.jsp</result>
<result name="deleteline_success">/test.jsp</result>
</action>
————————————————————————————————————————
lines.jsp 如下:
<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><s:text name="行车路线管理" /></title>
</head>
<body>
<div align="center">
<h1><font color=blue><s:text name="行车路线管理" /></font></h1>
<h2><font color=red><s:text name="删除路线"/></font></h2>
<s:form name="deleteLine" action="deleteLine">
<s:textfield name="lineId" key="lid"/>
<br>
<s:submit key="submit"/>
</s:form>
</div>
</body>
</html>
解决方案 »
- spring源码,不明白什么时候用cglib实例化类
- ejb从jboss 到 WebLogic 转换的样式表
- ServletActionContext.getRequest ()的问题
- 关于spring中使用ehcache的问题[缓存文件大小都是0]
- structs中实现文件上传。有兴趣的麻烦指导一下。
- 使用java连接oracle9i过程中如何设置权限???
- 关于hibernate中lazy="true"的问题。
- 在线等:EJB2.0 Upgrade for weblogic server6.0 怎么得到?
- 初学者请教......急急急
- spring-mybatis配置问题导致启动报错
- 【struts2环境求助】struts2运行时服务器启动不了
- 听说标题要很长才有人回答问题???????~~~~长不长??????
applicationContext.xml 如下:
<bean name="DeleteLine" class="com.action.DeleteLineAction">
<property name="mgr" ref="mgr"></property>
</bean>
applicationContext.xml这里面没有lineDAO啊。
测试对user表【int id(自增),varchar username,varchar password】的保存
还是报错,错误如下:
exceptionjava.lang.NullPointerException
com.action.SaveAction.execute(SaveAction.java:22)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SaveAction:
package com.action;import com.dao.UserDAO;
import com.domain.Users;
import com.opensymphony.xwork2.ActionSupport;public class SaveAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String username;
private String password;
private UserDAO userDAO;
public String execute() throws Exception {
Users user= new Users();
user.setUsername(username);
user.setPassword(password);
if(user.getUsername()!=null)
System.out.println(user.getUsername());
userDAO.save(user);
return SUCCESS;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
save方法
public void save(Users user)
{
getHibernateTemplate().save(user);
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="saveAction" class="com.action.SaveAction">
<result name="success">/saveSucc.jsp</result>
<result name="input">/saveErr.jsp</result>
</action>
</package>
</struts>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
applicationContext.xml
<bean id="UserDAO" class="com.dao.impl.UserDAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="Save" class="com.action.SaveAction">
<property name="userDAO" ref="UserDAO"/>
</bean>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
index.jsp
<body>
<div align="center">
<h1><font color="red">Main Menu</font></h1>
<a href="save.jsp">Save</a>
<br>
</div>
</body>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
save.jsp
<body>
<div align="center">
<h2><font color="blue">保存用户</font></h2>
<s:form name="saveUser" action="saveAction">
<s:textfield name="username" key="name"/>
<s:password name="password" key="word"/>
<s:submit key="save"/>
</s:form>
</div>
</body>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
最开始看看lineId有没拿到
}
一步步调试下先
这里的mgr是不是NULL