1.新建web project,一步步next,到第三步选择创建web.xml文件
2.粘贴下载好的struts2 jar包到web-inf--------lib下
3.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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>struts2_test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
4.在Java Resourse-------src下新建package,在package中新建HelloWorld类
HelloWorld.java
package struts2_test.action;
import com.opensymphony.xwork2.Action;
public class HelloWorld implements Action{
private String message;
public String getMessage(){
return message;
}
@Override
public String execute() throws Exception{
message="Hello World!";
return SUCCESS;
}
}
5.在src下新建struts.xml( new----搜索xml----新建struts.xml)
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="getMessage" class="struts2_test.action.HelloWorld">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>