github项目地址,https://github.com/bsqql123/structs-demo
建议clone下来,在本地进行调试。
参考文章:https://www.mkyong.com/struts2/struts-2-hello-world-example/
整个项目结构如下:
build.gradle配置
group 'me.iceblue'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
/*jsp*/
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
// https://mvnrepository.com/artifact/org.apache.struts/struts2-core
compile group: 'org.apache.struts', name: 'struts2-core', version: '2.5.5'
}
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.locale" value="zh_CN"></constant>
<package name="hurricane" extends="struts-default">
<action name="loginAction" class="controller.IndexController" method="execute">
<result>
/result.jsp
</result>
</action>
</package>
</struts>
IndexController.java如下
package controller;
import com.opensymphony.xwork2.ActionSupport;
/**
* Created by iceblue on 2017/2/17.
*/
public class IndexController extends ActionSupport {
public String Name;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
}
result.jsp如下
<%--
Created by IntelliJ IDEA.
User: iceblue
Date: 2017/2/17
Time: 0:07
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<h1>This is the result.jsp</h1>
</body>
</html>