[url="http://czj4451.iteye.com/blog/1535731"]一. spring JPA struts 整合开发(1) - spring集成JPA[/url]
二. spring JPA struts 整合开发(2) - spring集成struts
[size=medium]1. 在web.xml中加入struts配置和spring实例化配置[/size]
[size=medium]2. 拷贝struts-config.xml到/WEB-INF目录下:[/size]
在beans.xml中,加入:
[size=medium]3. com.john.web.action.PersonListAction类:[/size]
[size=medium]4. 创建result.jsp[/size]
[size=medium]5. 测试[/size]
在web server上运行该项目,往数据库插入几条数据。
输入http://localhost:[port name]/[project name]/person/list.do,查看效果
[size=medium]6. struts1.3的中文乱码问题以及因session关闭导致的延迟加载例外问题[/size]
参看:[url="http://czj4451.iteye.com/blog/1535279"]spring hibernate struts 整合开发(6) - 额外功能[/url]
整理自:传智播客spring教程
二. spring JPA struts 整合开发(2) - spring集成struts
[size=medium]1. 在web.xml中加入struts配置和spring实例化配置[/size]
<!-- Specify the config file of spring, would search the web root folder by default, -->
<!-- It's practical to use classpath provided by spring to search from source folder -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<!-- Instantiate the spring container -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Register struts as a servlet -->
<servlet>
<servlet-name>struts</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>struts</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
[size=medium]2. 拷贝struts-config.xml到/WEB-INF目录下:[/size]
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<action-mappings>
<!-- Let the action be managed by spring, thus the type property is removed -->
<action path="/person/list">
<forward name="list" path="/WEB-INF/pages/person_list.jsp"/>
</action>
</action-mappings>
<controller>
<!-- A process that will fetch the instance of the specific action from spring by value of the path -->
<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
</controller>
</struts-config>
在beans.xml中,加入:
<!-- Let spring manage the action -->
<bean name="/person/list" class="com.john.web.action.PersonListAction"/>
[size=medium]3. com.john.web.action.PersonListAction类:[/size]
public class PersonListAction extends Action {
// Now that the action is instantiated by spring, which will inject the property with instance
@Resource PersonService personService;
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("list", personService.getPersons());
return mapping.findForward("list");
}
}
[size=medium]4. 创建result.jsp[/size]
<body>
${message}
</body>
[size=medium]5. 测试[/size]
在web server上运行该项目,往数据库插入几条数据。
输入http://localhost:[port name]/[project name]/person/list.do,查看效果
[size=medium]6. struts1.3的中文乱码问题以及因session关闭导致的延迟加载例外问题[/size]
参看:[url="http://czj4451.iteye.com/blog/1535279"]spring hibernate struts 整合开发(6) - 额外功能[/url]
整理自:传智播客spring教程