您的位置:首页 > 编程语言 > Java开发

Struts2同时处理.do/.action后缀的请求

2015-01-08 16:58 302 查看
首先在 web.xml
 配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"

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_3_0.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>*.do</url-pattern>

<url-pattern>*.action</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.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.action.extension" value="do,action"/>

<package name="login" extends="struts-default" namespace="/">
<action name="login*" class="code.common.action.LoginAction" method="login_{1}">
<result name="success">/page/default/login_success.jsp</result>
<result name="failure">/page/default/login_failure.jsp</result>
</action>
</package>
</struts>

这样struts就可以支持.do/.action后缀的请求。



 

转自:http://chy2z.blog.163.com/blog/static/316688462013721111929150/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struts2