添加 spring-struts-3.2.9.RELEASE.jar

struts-config.xml 添加

    <controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor"></set-property>
</controller>

applicationContext.xml

    <!--配置 action-->
<bean name="/login" class="k.action.LoginAction" scope="prototype"/>
<bean name="/employee" class="k.action.EmployeeAction" scope="prototype"/>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans>
<form-bean name="employeeForm" type="k.form.EmployeeForm">
<form-property name="id" type="java.lang.Integer"></form-property>
<form-property name="name" type="java.lang.String"></form-property>
<form-property name="password" type="java.lang.String"></form-property>
</form-bean>
</form-beans> <global-forwards>
<forward name="ok" path="/WEB-INF/jsp/ok.jsp"></forward>
<forward name="err" path="/WEB-INF/jsp/err.jsp"></forward>
</global-forwards> <action-mappings>
<action name="employeeForm" path="/login" parameter="action" type="k.action.LoginAction"
scope="request" attribute="employeeForm" input="index.jsp" validate="false">
<forward name="main" path="/WEB-INF/jsp/main.jsp"></forward>
<forward name="loginJsp" path="/WEB-INF/jsp/login.jsp"></forward>
</action>
<action name="employeeForm" path="/employee" parameter="action" type="k.action.EmployeeAction"
scope="request" attribute="employeeForm" input="index.jsp" validate="false">
<forward name="addEmployeeUI" path="/WEB-INF/jsp/addEmployeeUI.jsp"></forward>
<forward name="loginJsp" path="/WEB-INF/jsp/login.jsp"></forward>
</action>
</action-mappings> <controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor"></set-property>
</controller> </struts-config>

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"
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.0.xsd "> <!-- 加载db.properties文件 -->
<bean id="config" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations" value="classpath*:*.properties"/>
</bean> <!-- 配置配置数据库信息(替代mybatis的配置文件conf.xml) -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
<property name="initialSize" value="${initialSize}"></property>
<property name="maxActive" value="${maxActive}"></property>
<property name="maxIdle" value="${maxIdle}"></property>
<property name="minIdle" value="${minIdle}"></property>
</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- //加载实体类的映射文件位置及名称 -->
<property name="mappingLocations" value="classpath:k/bean/*.hbm.xml"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean> <!--事务-->
<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!--开启注解配置-->
<context:annotation-config/> <!--配置 action-->
<bean name="/login" class="k.action.LoginAction" scope="prototype"/>
<bean name="/employee" class="k.action.EmployeeAction" scope="prototype"/> <!--配置 Service-->
<bean name="testService" class="k.service.TestService"/>
<bean name="employeeService" class="k.service.impl.EmployeeServiceImpl"/>
<bean name="departmentService" class="k.service.impl.DepartmentServiceImpl"/> </beans>

LoginAction

public class LoginAction extends DispatchAction {

    @Resource
private EmployeeService employeeService; public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("loginJsp");
} public ActionForward doLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
EmployeeForm employeeOld = (EmployeeForm) form;
Employee employee = new Employee(Integer.parseInt(employeeOld.getId()), employeeOld.getPassword());
employee = employeeService.checkEmployee(employee);
if (employee != null) {
request.getSession().setAttribute("employee", employee);
return mapping.findForward("main");
}
return mapping.findForward("err");
} public ActionForward loginOut(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return super.execute(mapping, form, request, response);
}
}

【SSH】Spring 整合 Struts的更多相关文章

  1. spring 整合struts

    1.例子:未被spring整合 struts.xml 的配置文件 <constant name="struts.enable.DynamicMethodInvocation" ...

  2. SSH开发实践part4:Spring整合Struts

    1 好了,前面spring与hibernate的整合开发我们基本上讲完了,现在要开始服务层的开发,也就是处理事务的action,在这里我们需要引入spring与struts的整合.也就是将action ...

  3. Spring整合Struts的两种方式介绍

    1 使用Spring托管Struts Action 该种方式就是将Struts Action也视为一种Bean交给Spring来进行托管,使用时Struts的配置文件中配置的Action的classs ...

  4. 8 -- 深入使用Spring -- 7... Spring 整合 Struts 2

    8.7 Spring 整合 Struts2 8.7.1 启动Spring 容器 8.7.2 MVC框架与Spring整合的思考 8.7.3 让Spring管理控制器 8.7.4 使用自动装配

  5. spring整合struts

    整合目标:使用spring的bean管理struts action service. 整合步骤: 一.加入spring 1.加入spring jar包 2.配置web.xml文件 <contex ...

  6. Spring整合struts的配置文件存放问题

    只使用Spring的时候,我把applicationContext.xml是放在项目的src路径下的,这样使用ClassPathXmlApplicationContext很方便嘛 整合了struts之 ...

  7. spring 整合 struts

    struts配置 objectFactory 在struts.xml添加,用spring工厂管理action对象 <constant name="struts.objectFactor ...

  8. Spring入门(四)— 整合Struts和Hibernate

    一.Spring整合Struts 1. 初步整合 只要在项目里面体现spring和 strut即可,不做任何的优化. struts 环境搭建 创建action public class UserAct ...

  9. Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)

    1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...

随机推荐

  1. H3C接口管理配置

    一.接口批量配置 当多个接口需要配置某功能(比如shutdown)时,需要逐个进入接口视图,在每个接口执行一遍命令,比较繁琐.此时,可以使用接口批量配置功能,对接口进行批量配置,节省配置工作量. 1. ...

  2. 0002 增加APP配置

    创建好工程后的第一步就是配置APP,目前有两个APP,配置APP的步骤如下: 01 APP目录配置 01.1 在APP目录下创建Templates目录,用于存储模板文件 01.2 在APP目录下创建v ...

  3. Web渗透测试思路整理

    信息收集: 域名/IP 子域名列表 whois: 注册地址,注册人,联系方式等 whois反查: 同ip有哪些站点(旁注),同一个注册人注册了哪些域名 社工注册人信息 指纹识别: 操作系统及版本 数据 ...

  4. Centos7在防火墙中添加访问端口

    1.       查看jenkins启动状态命令:systemctl status Jenkins 保证jenkins启动,此处的状态为正在运行 2.       查看防火墙状态命令:systemct ...

  5. linux命令 EOF

    在shell脚本中,通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返回到主Shell. EOF只是一个分界符,当然也可以用abcde替 ...

  6. sql语句代码规范

    19年年底的时候领导一直强调代码规范化以前写代码的时候很随意后来越来越看自己写的代码难受逐渐的也像规范化走去,今天又学了一招记录分享一下 这张图就是以前写代码的时候正常情况很是杂乱无章 这张就是规范话 ...

  7. 通过django搭建一个简易的web页面(实现数据的查询、添加、修改、删除)

    一.创建django项目 通过命令创建: django-admin startproject 项目名称 创建app应用 python3 manage.py startapp 应用名 #这里manage ...

  8. day14 tar

    04. 系统中如何对文件进行压缩处理 压缩的命令 tar 压缩命令语法: tar zcvf /oldboy/oldboy.tar.gz 指定要压缩的数据文件 z 压缩的方式 为zip c 创建压缩包文 ...

  9. python修改文件后缀名

    修改文件后缀名 # -*- coding: utf-8 -*- import os # # 列出当前目录下所有的文件 # filedir = 'C:\\Users\\WT\\Desktop\\test ...

  10. Docker常用命令及脚本

    1.常用命令 docker          search centos                                #搜索镜像              pull centos   ...