Structs引入bean时报空指针异常
我现在搭建一个简单的SSH框架的实例,结果在Action中引入Bean的时候报空指针异常,希望有知道的回复下,万分感谢。

web.xml文件的内容:
applicationContext.xml的内容:
struts.xml的内容:
spring-service.xml的内容:
Student.java的内容:
TestAction.java的内容:

web.xml文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>SpringStructIBatis</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/service/spring-service.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
</servlet>
</web-app>
applicationContext.xml的内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
">
<bean id="configproperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:jdbc.properties" />
</bean>
</beans>
struts.xml的内容:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="comprehensive" namespace="/rpt/test" extends="base">
<action name="test" class="com.comprehensive.action.TestAction" method="toTestAction" >
<result>/jsp/test.jsp</result>
</action>
</package>
</struts>
spring-service.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" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean name="testStudent" class="com.comprehensive.model.Student" />
<bean name="testAction" class="com.comprehensive.action.TestAction" >
<property name="student">
<ref bean="testStudent" />
</property>
</bean>
</beans>
Student.java的内容:
package com.comprehensive.model;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private int num;
private String name;
private String address;
private char sex;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public void print(){
System.out.println("========");
}
}
TestAction.java的内容:
package com.comprehensive.action;
import com.comprehensive.model.Student;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private Student student;
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public String toTestAction(){
System.out.println("=======ceshi=======");
//引入的时候会报错
student.print();
return SUCCESS;
}
}
...全文
相关推荐
structs bean 标签
structs bean 标签的一点代码。希望对大家学习structs bean 标签有帮助
Structs In Action(chinese)
一本讲Structs 的好书
基于structs的login
基于structs的登录系统,源代码
structs教程,spring_struts_hibernate
对structs的简介,文本格式 spring_struts_hibernate的介绍,PDF格式, 适合想对其有大概了解的人
Ibatis+Spring2.5+Structs2.0整合的一个小例子
使用Ibatis,Spring,Structs整合做的一个小例子,实现增,删,查的功能。


