java类
package cn.hb.si;
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport{
private HttpServletRequest request;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("执行Action");
//返回string 可以理解为视图的路径
return SUCCESS;
}
}
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" version="3.0">
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd" >
<struts>
<!-- 首先需要配置包名 包里面可以有多个action的 -->
<package name="default" namespace="/" extends="struts-default">
<action name="helloWord" class="cn.hb.si.HelloAction">
<result>/result.jsp</result>
</action>
</package>
</struts>
自己在WebRoot下面创建对应的jsp页面
访问地址
http://localhost:8080//Struts2_1zixue/helloWord.action