spring JPA struts 整合开发(2) - spring集成struts
[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] [code="xml"] contextConfigLocation classpath:beans.xml org.springframework.web.context.ContextLoaderListener struts org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml 0 struts *.do [/code] [size=medium]2. 拷贝struts-config.xml到/WEB-INF目录下:[/size] [code="xml"] [/code] 在beans.xml中,加入: [code="xml"] [/code] [size=medium]3. com.john.web.action.PersonListAction类:[/size] [code="java"] 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"); } } [/code] [size=medium]4. 创建result.jsp[/size] [code="html"] ${message} [/code] [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教程