添加 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. scanf使用尿性

    scanf("xxx%d",&xx); "xxxx%d" 这里不能乱写,这里是标准输入,不然xx的一直不对,和printf不一样,而且%d 和& ...

  2. [CF235A] LCM Challenge - 贪心

    找到3个不超过n的正整数(可以相同),使得它们的lcm(最小公倍数)最大. Solution 可以做得很优雅吧,但我喜欢(只会)暴力一点 根据质数密度分布性质,最后所取的这三个数一定不会比 \(n\) ...

  3. Qtree1 - 树链剖分

    树剖裸题?(复习练练手) // luogu-judger-enable-o2 #include <bits/stdc++.h> using namespace std; ],size[], ...

  4. Feign 不能注入报错及接口参数问题

    无法实例 解决方案: @EnableFeignClients(basePackages = "com.test.test.service") 要指定路径, 如果有设置@Compon ...

  5. eclipse unable to start within 45 seconds

    在eclipse4.8.2中运行tomcat8.5项目时,提示出错: Server Tomcat v8.0 Server at localhost was unable to start within ...

  6. nodemon:无法将“nodemon”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。

    主要问题还是你的终端(也就是你的nodemon命令执行的地方没有这个环境) 解决方法:设置全局的nodemon,在终端执行 npm install -g nodemon

  7. MySQL 分组并多行拼接 group_concat 用法

    数据源 user name     age 小红 18 小明 18 小芳 19 ------------------------------------------------------------ ...

  8. 关于vue 里:class 的几种使用方式

    最近一直在做vue项目 从网上搜索到的资料不太多.关于:class的使用 结合自己的实现 整理如下.接下来一篇写:style .其实从:class 这里可以想到:style的使用 也是类似的 一 cl ...

  9. 论Mac与windows的STS下的路径问题

    mac下的 <!-- javaBean生成在哪里 --> <javaModelGenerator targetPackage="com.atcrowdfunding.bea ...

  10. AcWing 1023. 买书 完全背包

    //完全背包 求方案数目 //f[i][j] 只从前i个物品中选,且总体积恰好为j的方案的集合 //f[i][j]=f[i-1][j]+f[i-1][j-v*1]+f[i-1][j-v*2]+...f ...