日期:2014-05-17 浏览次数:20688 次
<bean id="UserInfoDAO" class="test.dao.impl.UserInfoDAO" scope="prototype"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- 业务逻辑层注入 --> <bean id="UserInfoService" class="test.service.impl.UserInfoService" scope="prototype"> <property name="userInfoDAO" ref="UserInfoDAO" /> </bean> <!-- Action注入 --> <bean id="userAction" class="test.action.UserInfoAction" scope="prototype"> <property name="userService" ref="UserInfoService"/> </bean>
<struts> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.devMode" value="false" /> <include file="example.xml"/> <package name="default" namespace="/" extends="struts-default"> <action name="userAction" class="userAction"> <result name="success">/showAll.jsp</result> </action> </package> <!-- Add packages here --> </struts>
<!-- 加载时加载所有spring配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <!-- 拦截器 拦截客户所有请求 --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
public class UserInfoAction extends ActionSupport { private UserInfoService userService; private UserInfo user; @Override public String execute() throws Exception { if(userService.getUserInfoByName(user)) { System.out.println("成功"); return SUCCESS; } return null; } public UserInfo getUserInfo() { return user; } public void setUserInfo(UserInfo user) { this.user = user; } public void setUserService(UserInfoService userService) { this.userService = userService; } }