WEB.XML
```<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
JAVA代码
package com.Struts2;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String mes;
public String getMes() {
return mes;
}
public void setMes(String mes) {
this.mes = mes;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
mes="HELLO";
return SUCCESS;
}
}
```
jsp
```<%@ page language="java" contentType="text/html; utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>
HELLO
</h1>
</body>
</html>
struts.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>
<package name="default" extends="struts-default">
<action name="Hello" class="com.Struts2.HelloWorldAction">
<result name="success">index.jsp</result>
</action>
</package>
</struts>
```
排版有点乱
开发环境食tomcat9+jdk8
struts的版本问题