ssh之雇员管理系统(5)-将struts+spring整合
2013-05-14 13:05
447 查看
四、让web.xml中在tomcat启动的时候去实例化spring容器和struts
在web.xml中增加下面这个就可以实例化spring容器
<!-- 对Spring容器进行实例化 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
View Code
在web.xml中增加下面这个就可以实例化spring容器
<!-- 对Spring容器进行实例化 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
package com.wang.web.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import com.wang.domain.Employee; import com.wang.service.interfaces.EmployeeServiceInter; import com.wang.web.form.EmployeeForm; public class LoginAction extends DispatchAction { /** * 当一个请求发来时次方法将被执行 */ public ActionForward login(ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //下面这段话既可以代替ApplicationContext ac = new AplicationContext("xxx.xml"); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext (this.getServlet().getServletContext()); //得到验证的bean,由于是面向接口编程,所以我们用到接口 EmployeeServiceInter employeeServiceInter = (EmployeeServiceInter)ctx.getBean("employeeService"); //通过ActionForm,获取表单的值 EmployeeForm employeeForm = (EmployeeForm) form; Employee e = new Employee(); //从表单中获取值,set到Employee中 e.setId(Integer.parseInt(employeeForm.getId())); e.setPwd(employeeForm.getPwd()); //通过逻辑去验证 e = employeeServiceInter.vlidateEmployee(e); if(e !=null){ //e不为空,把雇员e添加到session中便于页面用到 request.getSession().setAttribute("loginuser", e); return map.findForward("ok"); }else { return map.findForward("err"); } } public ActionForward loginout(ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub return super.execute(map,form,request,response); } }
View Code
相关文章推荐
- Spring 雇员管理系统SSH 4
- Spring 雇员管理系统SSH 6
- 【Struts2+Hibernate3+Spring3】利用SSH整合,完成打印用户表,用户登录、注册、修改密码系统
- ssh之雇员管理系统(1)-spring测试
- Spring 雇员管理系统SSH 5
- 【Struts2+Hibernate3+Spring3】利用SSH整合,完成打印用户表,用户登录、注册、修改密码系统
- 基于spring4.3+hibernate5.1+Struts2.5整合的个人记账管理系统
- Spring 雇员管理系统SSH 1
- 【SSH】:基于Struts2+HIbernate3+Spring3实现员工管理系统之框架整合篇
- Spring 雇员管理系统SSH 3
- Eclipse下面的Maven管理的SSH框架整合(Struts,Spring,Hibernate)
- Struts+Spring+Hibernate/SSH整合开发详细一
- Struts+Spring+Hibernate--SSH整合实例
- Struts2.2.1 Spring3.0.4 Hibernate3.6 整合 附加springside3 [ss2h ss3 ss2hss3 ssh2 s2sh]
- Struts+Spring+Hibernate--SSH整合实例
- [原]Java web学习系列之 Java web开发中的SSH整合(Struts、Spring、Hibernate)(上)
- ssh之雇员管理系统(10)-分页实现
- 雇员管理系统-SSH版(一)