【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
@JFinal 你好,想跟你请教个问题:
是这样的,我自己创建了一个ssh框架,但是在action类中,注解service的时候就出现了问题:
问题描述:
编译运行的时候控制台没有任何错误,但是提交数据之后,表单能正常接收,此时页面就会出现在这个问题
我的具体思路是这样
首先在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"
version="2.5">
<display-name></display-name>
<welcome-file-list>
<welcome-file>Regist.jsp</welcome-file>
</welcome-file-list>
<!--spring中applicationContext加载方法:此处需要自定义加载 -->
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>/WEB-INF/classes/applicationContext-*.xml </param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!--strut2配置信息 -->
<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>/*</url-pattern>
</filter-mapping>
</web-app>
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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
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-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<!-- 使用Annocation,自动注解bean,并保证@Autowired,@Resource属性能够注入 -->
<context:annotation-config />
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<context:component-scan base-package="com.gsww.study"></context:component-scan>
<!--使用属性文件占位符 -->
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
</beans>
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>
<constant name="struts.objectFactory" value="spring" />
<package name="default" namespace="/" extends="struts-default">
<action name="AddAction" class="com.gsww.study.action.AddAction">
<result name="success">/index.jsp</result>
<result name="error">/post.jsp</result>
</action>
</package>
</struts>
表单:
<body>
<form action="AddAction" method="post">
<input type="text" name="person.username" value=""/>
<input type="text" name="person.age" value=""/>
<input type="text" name="person.salary" value=""/>
<input type="submit" name="submit" value="添加"/>
</form>
Action类:
public class AddAction extends ActionSupport{
private static final long serialVersionUID = 1L;
@Resource
private static UserOperationService userOperationService;
private Person person;
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
@Override
public String execute() throws Exception {
Person p=new Person();
p.setUsername(person.getUsername());
p.setAge(person.getAge());
p.setSalary(person.getSalary());
System.out.println(p.getUsername()+"----"+p.getAge()+"--"+p.getSalary());
if(userOperationService.add(p))
{
return SUCCESS;
}
return ERROR;
}
}
service类
import java.util.List;
import org.springframework.stereotype.Service;
import com.gsww.study.entity.Person;
import com.gsww.study.service.UserOperationService;
@Service("userOperationService")
public class UserOperationServiceImp implements UserOperationService {
@Override
public boolean add(Person person) {
System.out.println("------------------------------");
return true;
}
}
求大神看一下!我觉得问题应该是strut2和spring不能配合,但是我已经将action交给spring管理了,<constant name="struts.objectFactory" value="spring" />,现spring容器中有bean,但是就是action中无法注入,运行的时候只会在页面上显示空指针错误,控制台没有任何异常显示,谢谢大神。
???不是JFinal的问题你也@波总?估计波总真的是无奈了
既然ssh不行 那就转成JFinal不就好了