参考:https://blog.youkuaiyun.com/snowwitch/article/details/50954523
1.首先配置Tomcat,我这里用的是eclipse,Windows->Preferences->Server->Runtime Environment
2.点击add,然后打开Apache,这里我选的是Apache Tomcatv8.0,next
3.你们根据自己的情况选择合适的jre,这里我选的是jre1.8,Finish
4,接下来我们新建一个web project,由于我已经建过了一个,这里就不演示步骤啦~
5.将struct2配置所需的包导入WebContent,下载地址:点击打开链接
6.在WEB-INF下新建一个web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>S2SH</display-name>
<filter>
<filter-name>struts2</filter-name><!--这里的名字要和下面一致 -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
7.在src下新建一个类TestAction,继承ActionSupport类,该类有数据校验的作用
package com.Demons.action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport {
public String execute() throws Exception {
System.out.println("structs==================");
return "success";
}
}
8.接下来在src下建立structs.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<structs>
<package name="default" extends="structs-default">
<action name="login" class="com.Demons.action.TestAction">
<result name="success">index.jsp</result>
</action>
</package>
</structs>
9,在WebContent下建立index.jsp,在body里面写上测试的句子,我写的是HelloWorld!!,接下来就可以点击运行啦~