一.Struts介绍
Struts是Apache软件基金会(ASF)赞助的一个开源项目。它最初是jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目。它通过采用JavaServlet/JSP技术,实现了基于JavaEEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品。
二.搭建环境(使用Intellij IDEA+maven+struts2)
1.创建maven+struts2项目
2.添加配置文件,自动下载必要jar包
org.apache.struts
struts2-core
2.5.10.1
3.webxml中引入struts核心功能——配置过滤器
4.开发action
5.配置action——src/struts.xml
1.创建maven+struts2项目步骤:
1).创建Maven项目:maven快速入门
2).设置Groupld和Artfactld名称
2.添加配置文件,自动下载必要jar包
commons-fileupload-1.2.2.jar 【文件上传相关包】
commons-io-2.0.1.jar
struts2-core-2.3.4.1.jar 【struts2核心功能包】
ognl-3.0.5.jar 【Ognl表达式功能支持表】
commons-lang3-3.1.jar 【struts对java.lang包的扩展】
freemarker-2.3.19.jar 【struts的标签模板库jar文件】
javassist-3.11.0.GA.jar 【struts对字节码的处理相关jar】
配置文件引入
org.apache.struts
struts2-core
2.5.10.1
3.webxml中引入struts核心功能——配置过滤器
web.xml
/p>
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
Archetype Created Web Application
struts2
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.jsp
4.开发action
LoginAction.java
package com.huan.struts.action;
/**
* Created by 马欢欢 on 2017/6/19.
*/
public class LoginAction {
public String success(){
System.out.println("成功访问action,请求正在处理中");
System.out.println("调用service");
return "success";
}
}
success.jsp
Created by IntelliJ IDEA.
User: 马欢欢
Date: 2017/6/19
Time: 21:49
To change this template use File | Settings | File Templates.
--%>
success成功跳转到该页面5.配置action——src/struts.xml
struts2.xml
/p>
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
success.jsp
启动成功
访问成功
成功访问
控制台打印