Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(二)——Struts2集成
1、 pom.xml文件添struts2依赖jar包;
<!-- 与Struts2集成必须使用 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.4.RELEASE</version>
</dependency> <!-- Struts2的核心包 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.16</version>
</dependency> <!-- Struts2和Spring整合插件 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.4.1</version>
</dependency>
2、 web.xml文件添加struts2拦截器;
<!-- Struts2的核心过滤器配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- Struts2过滤器拦截所有的.action请求 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
3、 src/main/resources目录下添加struts.xml文件;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts> <!-- 指定由spring负责action对象的创建 -->
<constant name="struts.objectFactory" value="spring"/>
<!-- 所有匹配*.action的请求都由struts2处理 -->
<constant name="struts.action.extension" value="action"/>
<!-- 是否启用开发模式(开发时设置为true,发布到生产环境后设置为false) -->
<constant name="struts.devMode" value="true" />
<!-- struts配置文件改动后,是否重新加载(开发时设置为true,发布到生产环境后设置为false) -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 设置浏览器是否缓存静态内容(开发时设置为false,发布到生产环境后设置为true) -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 请求参数的编码方式 -->
<constant name="struts.i18n.encoding" value="utf-8" />
<!-- 每次HTTP请求系统都重新加载资源文件,有助于开发(开发时设置为true,发布到生产环境后设置为false) -->
<constant name="struts.i18n.reload" value="true" />
<!-- 文件上传最大值 -->
<constant name="struts.multipart.maxSize" value="104857600" />
<!-- 让struts2支持动态方法调用,使用叹号访问方法 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- Action名称中是否还是用斜线 -->
<constant name="struts.enable.SlashesInActionNames" value="false" />
<!-- 允许标签中使用表达式语法 -->
<constant name="struts.tag.altSyntax" value="true" />
<!-- 对于WebLogic,Orion,OC4J此属性应该设置成true -->
<constant name="struts.dispatcher.parametersWorkaround" value="false" /> <include file="strutsLogin.xml"/> <package name="basePackage" extends="struts-default">
</package> </struts>
4、 添加Action测试类;
package com.coshaho.learn.action; import java.util.HashMap;
import java.util.Map; import org.springframework.stereotype.Controller; @Controller("login")
public class LoginAction
{
private static Map<String, String> userMap = new HashMap<String, String>();
static
{
userMap.put("hekexu", "hekexu");
userMap.put("zhubing", "zhubing");
} private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} public String authority()
{
String curpassword = userMap.get(username); if(curpassword != null && curpassword.equals(password))
{
return "success";
} return "error";
}
}
5、 src/main/resources目录下添加strutsLogin.xml文件;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="framework" extends="struts-default" namespace="/framework">
<action name="login" class="login">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action> <action name="authority" class="login" method="authority">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
6、 添加登陆jsp文件;
login.jsp
<html>
<head>
<%String path = request.getContextPath();%>
</head>
<body>
<form action="<%=path%>/framework/authority.action" method="post">
UserName:<input type="text" name="username"/><p/>
Password:<input type="password" name="password"/><p/>
<input type="submit" name="submit"/>
</form>
</body>
</html>
success.jsp
<html>
<head>
</head>
<body>
<h2>Login successfully!</h2>
</body>
</html>
error.jsp
<html>
<head>
</head>
<body>
<h2>Login failure!</h2>
</body>
</html>
7、 发布工程,访问http://localhost:8080/FrameIntegrationWeb/login.jsp。


Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(二)——Struts2集成的更多相关文章
- Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)二
接着上一篇博客<Spring整合MyBatis(Maven+MySQL)一>继续. Spring的开放性和扩张性在J2EE应用领域得到了充分的证明,与其他优秀框架无缝的集成是Spring最 ...
- Spring+SpringMVC+MyBatis深入学习及搭建(十二)——SpringMVC入门程序(一)
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6999743.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十一)——S ...
- Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)一
MyBatis-Spring 会帮助你将 MyBatis 代码无缝地整合到 Spring 中. 使用这个类库中的类, Spring 将会加载必要的MyBatis工厂类和 session 类. 这个类库 ...
- (4)Maven快速入门_4在Spring+SpringMVC+MyBatis+Oracle+Maven框架整合运行在Tomcat8中
利用Maven 创建Spring+SpringMVC+MyBatis+Oracle 项目 分了三个项目 Dao (jar) Service (jar) Controller (web) ...
- intellij idea社区版 & maven & git & tomcat/jetty 的struts2项目的搭建
1.新建一个project,并在project下新建一个maven module.
- Spring+SpringMVC+MyBatis+easyUI整合优化篇(二)Log4j讲解与整合
日常啰嗦 上一篇文章主要讲述了一下syso和Log间的一些区别与比较,重点是在项目的日志功能上,因此,承接前文<Spring+SpringMVC+MyBatis+easyUI整合优化篇(一)Sy ...
- Spring+SpringMVC+MyBatis深入学习及搭建(十二)——SpringMVC入门程序
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6999743.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十一)--S ...
- Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)
http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...
- Spring+SpringMVC+MyBatis+easyUI整合基础篇(二)牛刀小试
承接上文,该篇即为项目整合的介绍了. 废话不多说,先把源码和项目地址放上来,重点要写在前面. github地址为ssm-demo 你也可以先体验一下实际效果,点击这里就行啦 账号:admin 密码:1 ...
- 搭建springboot的ssm(spring + springmvc + mybatis)的maven项目
最终项目目录结构 创建过程 1.创建开关SpringBootApplication 为了创建快速.我们使用idea自带的创建springboot来创建结构,当然创建普通的web项目也是可以的.(使用e ...
随机推荐
- How are you vs How are you doing
How are you与How are you doing,有何不同呢? 貌似没有不同…… 中国教科书式的回答是"Fine, thank you, and you?" 随便一点&q ...
- UPUPW本地环境配置thinkphp5的问题
问题解决参考: https://blog.csdn.net/lengyue1084/article/details/80001625 看httpd-vhosts.conf的配置: <Virtua ...
- IE new Date NaN 问题
var ctime = "2015/1/7 10:35"; ctime = ctime.replace(/-/g,"/"); //为了兼容IE var date ...
- function &w(){}
CodeIgniter 3.1.0 <?php //\system\core\Common.php function &load_class($class, $directory = ' ...
- rank() over,dense_rank(),row_number() 的区别
转自:https://jingyan.baidu.com/article/597035521ff2ec8fc107404b.html rank() over是的作用是查出指定条件后进行一个排名,但是有 ...
- 从0开始做一个的Vue图片/ 文件选择(上传)组件[基础向]
原文:http://blog.csdn.net/sinat_17775997/article/details/58585142 之前用Vue做了一个基础的组件 vue-img-inputer ,下面就 ...
- Redis添加历史浏览记录
参考资料 http://redisdoc.com/index.html http://redis-py.readthedocs.io/en/latest/#indices-and-tables 1.什 ...
- sysbench的安装和做性能测试
sysbench的安装和做性能测试 http://imysql.cn/node/312 sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况. ...
- PHP导出excel时数字变为科学计数的解决方法
在数据导出到excel时数字格式不对,一般分为以下两种情况. 1.excel单元格设置长度不够 解决方法: //在excel.php文件中 $objActSheet = $objPHPExcel-&g ...
- 深入理解Fabric环境搭建的详细过程(转)
前面的准备工作我就不用多说了,也就是各种软件和开发环境的安装,安装好以后,我们git clone下来最新的代码,并切换到v1.0.0,并且下载好我们需要使用的docker镜像,也就是到步骤6,接下来我 ...