一.STRUTS介紹
二.搭建環境(使用INTELLIJ IDEA+MAVEN+STRUTS2)
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】
配置檔案引入
<dependency>
<groupId>org.apache.strutsgroupId>
<artifactId>struts2-coreartifactId>
<version>2.5.10.1version>
dependency>
3.WEB.XML中引入STRUTS核心功能——配置過濾器
<web-app>
<display-name>Archetype Created Web Applicationdisplay-name>
<filter>
<filter-name>struts2filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilterfilter-class>
filter>
<filter-mapping>
<filter-name>struts2filter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<welcome-file-list>
<welcome-file>index.jspwelcome-file>
welcome-file-list>
web-app>
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.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>success成功跳轉到該頁面title>
head>
<body>
body>
html>
5.配置ACTION——SRC/STRUTS.XML
struts2.xml
<struts>
<package name="null" extends="struts-default">
<action name="login" class="com.huan.struts.action.LoginAction" method="success">
<result name="success">success.jspresult>
action>
package>
struts>
1.建立MAVEN+STRUTS2項目步驟:
1).建立Maven項目:maven快速入門
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】
配置檔案引入
pom.xml
<dependency>
<groupId>org.apache.strutsgroupId>
<artifactId>struts2-coreartifactId>
<version>2.5.10.1version>
dependency>
3.webxml中引入struts核心功能——配置過濾器
web.xml
<web-app>
<display-name>Archetype Created Web Applicationdisplay-name>
<filter>
<filter-name>struts2filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilterfilter-class>
filter>
<filter-mapping>
<filter-name>struts2filter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<welcome-file-list>
<welcome-file>index.jspwelcome-file>
welcome-file-list>
web-app>
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.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>success成功跳轉到該頁面title>
head>
<body>
body>
html>
5.配置ACTION——SRC/STRUTS.XML
struts2.xml
<struts>
<package name="null" extends="struts-default">
<action name="login" class="com.huan.struts.action.LoginAction" method="success">
<result name="success">success.jspresult>
action>
package>
struts>
原网址