添加 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. [USACO12FEB] 附近的牛 Nearby Cows - 树形dp,容斥

    给你一棵 \(n\) 个点的树,点带权,对于每个节点求出距离它不超过 \(k\) 的所有节点权值和 \(m_i\) 随便定一个根,设\(f[i][j]\)表示只考虑子树,距离为\(j\)的权值和,\( ...

  2. Echart的使用legend遇到的问题小记

    Echart的图标真的很漂亮,使用也相对简单.但是官网的配置项的例子我不是很能快速的使用,得思考一会.哈哈,可能我比较笨吧. 在作柱状图的时候,我是通过Ajax动态获取的数据,但是图例legend就是 ...

  3. Keep、小红书、美图…独角兽App能拿到新一轮救命钱吗?

    大多数人热爱手机,不是因为时尚的外观或者结实的零部件,而是因琳琅满目的App赋予其太多的功能.智能手机最先是清理掉人类的零碎时间,现如今又开始肢解我们大块的时间,或者说,智能手机本身就是生活.在如此背 ...

  4. C语言运算符的优先级与结合性

    结合性:左结合是从左到右依次执行,右结合是从右到左依次执行. 优先级 运算符 名称或作用 运算类型 结合方向 特点 1 () [] -> . 小括号运算符 下标运算符 指向结构成员运算符 结构成 ...

  5. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy

    //因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...

  6. Centos7 入门几个操作

    http://www.wallcopper.com/linux/1650.html 创建文件软连接 ln -s 源路径 目标路径 查看软连接ls -il 服务操作:systemctl start fo ...

  7. my bug of VG algorithm

    def visibility_graph(series): g = nx.Graph() # convert list of magnitudes into list of tuples that h ...

  8. Laravel 中使用 Laravel-Excel 美化

    <?php use Maatwebsite\Excel\Classes\LaravelExcelWorksheet; use Maatwebsite\Excel\Exceptions\Larav ...

  9. js时间相关操作

    取值 this.divEndDate.attr("value",new Date()); var date = new Date(); date.getYear():     取2 ...

  10. [Luogu]中位数

    Description Luogu1168 Solution 一种神奇的做法:开一个大根堆和小根堆,保证大根堆比小根堆多1个元素,且大根堆堆顶元素比小根堆堆顶元素小,那么大根堆堆顶就是中位数.插入的时 ...