<?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.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="username" value="ssi"/>
<property name="password" value="ssi"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
<property name="initialSize" value="1"/>
<property name="maxActive" value="4"/>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:SqlMapConfig.xml">
</property>
<property name="dataSource" ref="dataSource">
</property>
</bean><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean><bean id="sqlMapClientProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="select*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean><bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean><bean id="userDao" class="com.soft.ssi.dao.UserDaoImpl">
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
</bean><bean id="userService" class="com.soft.ssi.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userServicePrxy" parent="sqlMapClientProxyFactoryBean">
<property name="target" ref="userService"></property>
</bean><bean id="UserAction" class="com.soft.ssi.web.UserAction">
<property name="userService" ref="userService"></property>
</bean></beans>package com.soft.ssi.web;
import com.opensymphony.xwork2.ActionSupport;
import com.soft.ssi.po.UserInfo;
import com.soft.ssi.service.UserService;
public class UserAction extends ActionSupport{
private UserService userService;
private UserInfo userInfo;
public UserInfo getUserInfo() {
return userInfo;
} public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
} public UserService getUserService() {
return userService;
} public void setUserService(UserService userService) {
this.userService = userService;
}
public String execute() throws Exception {
return super.execute();
} public String regedit() throws Exception {
boolean flag = false;
System.out.println(userInfo);
System.out.println(this.userService);
flag = userService.insertUser(userInfo);
if(flag){
return "ok";
}else{
return "error";
}
}
}
userService对象为空
<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.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="username" value="ssi"/>
<property name="password" value="ssi"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
<property name="initialSize" value="1"/>
<property name="maxActive" value="4"/>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:SqlMapConfig.xml">
</property>
<property name="dataSource" ref="dataSource">
</property>
</bean><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean><bean id="sqlMapClientProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="select*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean><bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean><bean id="userDao" class="com.soft.ssi.dao.UserDaoImpl">
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
</bean><bean id="userService" class="com.soft.ssi.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userServicePrxy" parent="sqlMapClientProxyFactoryBean">
<property name="target" ref="userService"></property>
</bean><bean id="UserAction" class="com.soft.ssi.web.UserAction">
<property name="userService" ref="userService"></property>
</bean></beans>package com.soft.ssi.web;
import com.opensymphony.xwork2.ActionSupport;
import com.soft.ssi.po.UserInfo;
import com.soft.ssi.service.UserService;
public class UserAction extends ActionSupport{
private UserService userService;
private UserInfo userInfo;
public UserInfo getUserInfo() {
return userInfo;
} public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
} public UserService getUserService() {
return userService;
} public void setUserService(UserService userService) {
this.userService = userService;
}
public String execute() throws Exception {
return super.execute();
} public String regedit() throws Exception {
boolean flag = false;
System.out.println(userInfo);
System.out.println(this.userService);
flag = userService.insertUser(userInfo);
if(flag){
return "ok";
}else{
return "error";
}
}
}
userService对象为空
解决方案 »
- 一直报一个错误,大家看看给给意见
- Java 测试题 求解答 谢谢!!
- 如何用java来实现基于chord协议的p2p
- 把struts.xml存入src出现错误,图标不是xml图标 不能运行
- hibernate Criteria查询返回某些特定的列,如何实现?
- 如果有一个开源的架构需要你设计,你会怎么设计你的框架
- 求jsf页面之间的数据如何传递?
- 如何较好处理session timeout以后自动forward到一个jsp,登录后回到timeout前的页面
- 请教两个jboss的初级问题
- STRUTS 和SPRING 结合问题
- Hibernate连接SQL server2005 需要几个jar包 给个连接下载啊
- hibernate3.3+oracle11g的连接问题求解各位高手
<bean id="userService" class="com.soft.ssi.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
spring管理的是UserServiceImpl,而你action里写的是private UserService userService,它又不归spring管理,spring无法给你注入,所以为空
userService是接口userServiceImpl是实现类
是不是没有导入struts2-spring-plugin-xxx.jar包
2010-7-1 17:25:26 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.NullPointerException
at com.soft.ssi.web.UserAction.regedit(UserAction.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
这行报错 页面:<body>
<s:form action="regedit" method="post">
<s:textfield name="userInfo.username" label="用户名"></s:textfield><br>
<s:password name="userInfo.password" label="密码"></s:password><br>
<s:radio list="#{'1':'男','0':'女'}" name="userInfo.sex" label="性别"></s:radio>
<s:textfield name="userInfo.old" label="年龄"></s:textfield><br>
<s:submit value="提交"></s:submit>
</s:form>
</body>
<property name="userService" ref="userService"></property>
</bean>删了这个 试试看
装配模式你好象没写
后台有报错了么,如果没有报错应该是struts和spring的整合没有配置吧
<bean id="userDao" class="com.soft.ssi.dao.UserDaoImpl">
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>