1.eclipse新建了maven工程配置完pom.xml生成web.xml
点击这里生成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" version="2.5">
<display-name>ssh_01</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>strutsmvc</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<!-- 默认找src/struts.xml配置文件,找action和result配置 -->
<filter-mapping>
<filter-name>strutsmvc</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2.配置完web.xml,在webapp目录下写前台页面
3.struts.xml配置信息填写
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<!-- 将默认的.action扩展名改为.do -->
<constant name="struts.action.extension" value="do"></constant>
<!-- extends继承框架内部struts-default -->
<package name="demo1" extends="struts-default">
<!-- name指定为请求名;class指定action类;method指定action方法名,不写默认为execute -->
<action name="hello" class="cn.xdl.action.ShenMe" method="HaHaHa">
<!-- name对应action方法返回结果;type指定result组件类型 -->
<result name="success" type="dispatcher">
/hello.html
</result>
</action>
<action name="list" class="cn.xdl.action.Go" method="HaHaHa">
<!-- name对应action方法返回结果;type指定result组件类型 -->
<result name="success" type="dispatcher">
/list.jsp
</result>
</action>
</package>
</struts>