<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.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>*.action</url-pattern>
</filter-mapping></web-app>
这是在web.xml配置了struts2,只拦截后缀名为action的域,
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="user" namespace="" extends="struts-default">
<action name="user" class="com.liudw.UserAction">
<result>/MyJsp.jsp</result>
</action>
</package>
</struts>
struts.xml的配置情况,在action中,name的命名是不带任何后缀的,不然URI就会出错,
package com.liudw;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
另外,在jsp—>action—>jsp时,在第二个jsp如果还想跳转到其他页面的话,根目录就会变成是action在package中的namespace的目录名了。