我的页面代码是这样的:<html>
<head>
<title>公告添加</title>
</head>
<s:head/>
<body>
<h5 align="center">添加公告</h5>
<table align="center" border="1" width="40%">
<center>
<s:form action="dormNoticeControl!addNotice.action" >
<s:textfield name="dormNoticeinfo.title" label="公告题目"/>
<s:textfield name="dormNoticeinfo.type" label="公告类型"/>
<s:textarea name="dormNoticeinfo.content" rows="5" cols="20" label="公告内容"/>
<s:textfield name="dormNoticeinfo.issuer" label="发布人"/>
<s:textfield name="dormNoticeinfo.published" label="发布时间"/>
<tr>
<td colspan="2" align="center">
<s:submit theme="simple" value="保存"/>
<s:reset theme="simple" value="重置"/>
</td>
</tr>
</s:form>
</center>
</table>
</body>
</html>
DAO里的代码是这样的:public void addNotice(AbstractdormNoticeInfo dormNoticeinfo) { //添加新的公告
Session session=getSession();
Transaction tra=session.beginTransaction();
System.out.println("dormNotice="+dormNoticeinfo);
session.save(dormNoticeinfo);
tra.commit();
session.close();
}
运行结果报错如下:dormNotice=null
2010-7-4 9:00:38 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:40)
at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:23)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at com.txsm.crm.dao.impl.DormNoticeDAO.addNotice(DormNoticeDAO.java:20)
at com.txsm.crm.service.impl.DormService.addNotice(DormService.java:22)
at com.txsm.crm.action.DormNoticeAction.addNotice(DormNoticeAction.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
<head>
<title>公告添加</title>
</head>
<s:head/>
<body>
<h5 align="center">添加公告</h5>
<table align="center" border="1" width="40%">
<center>
<s:form action="dormNoticeControl!addNotice.action" >
<s:textfield name="dormNoticeinfo.title" label="公告题目"/>
<s:textfield name="dormNoticeinfo.type" label="公告类型"/>
<s:textarea name="dormNoticeinfo.content" rows="5" cols="20" label="公告内容"/>
<s:textfield name="dormNoticeinfo.issuer" label="发布人"/>
<s:textfield name="dormNoticeinfo.published" label="发布时间"/>
<tr>
<td colspan="2" align="center">
<s:submit theme="simple" value="保存"/>
<s:reset theme="simple" value="重置"/>
</td>
</tr>
</s:form>
</center>
</table>
</body>
</html>
DAO里的代码是这样的:public void addNotice(AbstractdormNoticeInfo dormNoticeinfo) { //添加新的公告
Session session=getSession();
Transaction tra=session.beginTransaction();
System.out.println("dormNotice="+dormNoticeinfo);
session.save(dormNoticeinfo);
tra.commit();
session.close();
}
运行结果报错如下:dormNotice=null
2010-7-4 9:00:38 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:40)
at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:23)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at com.txsm.crm.dao.impl.DormNoticeDAO.addNotice(DormNoticeDAO.java:20)
at com.txsm.crm.service.impl.DormService.addNotice(DormService.java:22)
at com.txsm.crm.action.DormNoticeAction.addNotice(DormNoticeAction.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
解决方案 »
- 面试题:基于SSH框架 或者 jsp+servlet+bean ,一个请求响应的过程(直接写访问的文件、步骤)
- spring开发:
- 为什么用junit测试能删除 加到Action类中就出问题了
- Excel 转换成 Html
- jsp标准动作中,value="${param.username}"的作用
- 如果上天在给你一次机会 ,你会选择Java开发吗
- XFire 复杂类型配置问题
- 请各位资深高人指教,小弟在青岛做J2EE工资能多少?
- 访问EJB时出错,请帮忙
- SQL Server2000在WebLogic中配置数据池的问题,烦请高手帮助解决!
- 公司要搭建个主流视频网站,请大家能否给点技术建议
- 那位大侠能写个Servlet例子吗?
at com.txsm.crm.service.impl.DormService.addNotice(DormService.java:22)
at com.txsm.crm.action.DormNoticeAction.addNotice(DormNoticeAction.java:34)看看出错信息找原因
我有get 和 set 方法啊
public class DormNoticeAction extends ActionSupport {
protected AbstractdormNoticeInfo dormNoticeinfo;// 实体类
protected IDormService dormService;
public String execute() throws Exception {
return null;
}
public String addNotice() throws Exception { //添加公告
System.out.println("在action里的dormNotice="+this.getDormNoticeinfo());
dormService.addNotice(this.getDormNoticeinfo());
return SUCCESS;
} public String deleteNotice() throws Exception { //删除公告
HttpServletRequest request=ServletActionContext.getRequest(); String strId=request.getParameter("id");
int id=Integer.parseInt(strId);
System.out.println("id="+id);
//dormNoticeinfo.setId(id);
//System.out.println("dormNoticeinfo="+dormNoticeinfo.toString());
//dormService.deleteNotice(dormNoticeinfo);
dormService.deleteNotice(id);
return SUCCESS;
}
public String preupdateNotice() throws Exception{ // 修改公告预处理
HttpServletRequest request=ServletActionContext.getRequest();
String strId=request.getParameter("id");
if(strId==null){
return ERROR;
}
else{
int id=Integer.parseInt(strId);
System.out.print("id="+id);
List list=new ArrayList();
list=dormService.selectNotice(id);
if(list.size()>0){
ActionContext act=ActionContext.getContext();
Map map=act.getSession();
map.put("updateNotice", list);
}
else return ERROR;
}
return "update";
}
public String updateNotice() throws Exception{
HttpServletRequest request=ServletActionContext.getRequest();
String strId=request.getParameter("id");
int id=0;
if(strId==null){
return ERROR;
}
else{
id=Integer.parseInt(strId);
}
dormNoticeinfo.setId(id);
dormService.updateNotice(dormNoticeinfo);
return SUCCESS;
}
public String selectNotice() throws Exception { //查询最新公告
List list=new ArrayList();
list=dormService.selectNotice(dormNoticeinfo);
if(list.size()>0){
ActionContext act=ActionContext.getContext();
Map map=act.getSession();
map.put("newNotice", list);
}
else{
return ERROR;
}
return "select";
}
//下面是get set方法
public AbstractdormNoticeInfo getDormNoticeinfo() {
return dormNoticeinfo;
}
public void setDormNoticeinfo(AbstractdormNoticeInfo dormNoticeinfo) {
this.dormNoticeinfo = dormNoticeinfo;
}
public IDormService getDormService() {
return dormService;
}
public void setDormService(IDormService dormService) {
this.dormService = dormService;
}
}
Session session=getSession();
Transaction tra=session.beginTransaction();
System.out.println("dormNotice="+dormNoticeinfo);
session.save(dormNoticeinfo);
tra.commit();
session.close();
}
dormNoticeinfo有get 和set方法吗?如果有,把public void addNotice(AbstractdormNoticeInfo dormNoticeinfo)改成public void addNotice()看看!
public void setDormNoticeinfo(AbstractdormNoticeInfo dormNoticeinfo) {
this.dormNoticeinfo = dormNoticeinfo;
}
设置断点,看是否执行,还有看你的action是不是单例的,如果是的话,你在前面执行该action时候,是否有给dormNoticeinfo注入值,如果没有,你又使用的是单例,那么就很有可能是你的action已经实例化了,后面再执行add时候,调用已经实例化的action,而实例化的时候又没有给dormNoticeinfo注入值。所以出错
个人猜测,不知道对不
action里就没有获得数据啊
我好象不会什么加断点调试的
看你的action是不是单例的,如果是的话,你在前面执行该action时候,是否有给dormNoticeinfo注入值,如果没有,你又使用的是单例,那么就很有可能是你的action已经实例化了,后面再执行add时候,调用已经实例化的action,而实例化的时候又没有给dormNoticeinfo注入值。所以出错
你的action是用spring管理的吧,spring对于实例化有単例和多例的说话,楼主懂不?
System.out.print("这里是否成功运行到????? get方法 ");
return dormNoticeinfo;
}
public void setDormNoticeinfo(AbstractdormNoticeInfo dormNoticeinfo) {
this.dormNoticeinfo = dormNoticeinfo;
System.out.print("这里是否成功运行到????? set方法");
}
结果控制台打印出:信息: Server startup in 7167 ms
这里是否成功运行到????? get方法 这里是否成功运行到????? get方法 这里是否成功运行到????? get方法 这里是否成功运行到????? get方法 这里是否成功运行到????? get方法 这里是否成功运行到????? get方法 在action里的dormNotice=null
这里是否成功运行到????? get方法 sessionFactory=org.hibernate.impl.SessionFactoryImpl@106bde8
dormNotice=null
<bean id= "dormNoticeAction " class= "com.txsm.crm.action.DormNoticeAction " scope="protype",protype不知道写对没有,你去看看spring的bean的原子性