报500错误,求教啊~~

sinat_23001607 2014-11-06 09:34:44
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
com.test.action.SaveUserAction.execute(SaveUserAction.java:23)
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:585)


SaveUserAction.java

private User user;
private UserService userService;
public UserService getUserService() {
return userService;
}

public void setUserService(UserService userService) {
this.userService = userService;
}

@Override
public String execute() throws Exception {
// System.out.println(user.getFirstname());
// System.out.println(user.getLastname());
// System.out.println(user.getAge());
userService.saveUser(user);
return SUCCESS;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}


println出来是有值的,但为什么还是要空指针呢?user里面还有个自增的ID,难道和这个有关系?
...全文
128 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinat_23001607 2014-11-06
  • 打赏
  • 举报
回复
谢谢大家,晕死,原来少了个jar包,struts2-spring-plugin,提示也太不明显了。。。
tony4geek 2014-11-06
  • 打赏
  • 举报
回复
只有debug 看看。你action userService 打印呢
sinat_23001607 2014-11-06
  • 打赏
  • 举报
回复
引用 8 楼 rui888 的回复:
你 userService 进去没?
没有,userService里面的println没有打印,郁闷死了,好像好好练SSH,弄个struts就1天
xuefeng0707 2014-11-06
  • 打赏
  • 举报
回复
StrutsSpringObjectFactory有没有配?struts.xml里的Action类名是怎么配的?
tony4geek 2014-11-06
  • 打赏
  • 举报
回复
你 userService 进去没?
sinat_23001607 2014-11-06
  • 打赏
  • 举报
回复
引用 6 楼 rui888 的回复:
你一步步调试看看/
我试了debug,不能走下去,很奇怪,于是在service和dao里分别加上println语句,但却不执行,应该是没有进到userService.saveUser(user),因为空指针所以不进去了?又是哪个是空指针呢,user?
tony4geek 2014-11-06
  • 打赏
  • 举报
回复
你一步步调试看看/
sinat_23001607 2014-11-06
  • 打赏
  • 举报
回复
引用 4 楼 rui888 的回复:
你打印看看。还有user 也看看。
hello world 20 com.test.bean.User@1f568f
tony4geek 2014-11-06
  • 打赏
  • 举报
回复
你打印看看。还有user 也看看。
sinat_23001607 2014-11-06
  • 打赏
  • 举报
回复
难道是我配置不对? applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/ssh2"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="dailet">org.hibenate.dailect.MySQLDailect</prop> <prop key="show_sql">true</prop> <prop key="format_sql">update</prop> </props> </property> <property name="mappingResources"> <list> <value>com/test/bean/Users.hbm.xml</value> </list> </property> </bean> <bean id="userDao" class="com.test.dao.impl.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="userService" class="com.test.service.impl.UserServiceImpl"> <property name="userDao" ref="userDao"></property> </bean> <bean id="userAction" class="com.test.action.SaveUserAction" scope="prototype"> <property name="userService" ref="userService"></property> </bean> </beans>
sinat_23001607 2014-11-06
  • 打赏
  • 举报
回复
引用 1 楼 rui888 的回复:
你 userService 没有注册成功。
不是吧,你哪里看出来service没有注册成功?
tony4geek 2014-11-06
  • 打赏
  • 举报
回复
你 userService 没有注册成功。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧