我在struts2下配置urlrewrite,步骤如下:
下载urlrewrite-2.6.0.jar到WEB-INF
-
在web.xml添加以下代码
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">BuGu
index.html
contextConfigLocation
classpath:spring.xml
org.springframework.web.context.ContextLoaderListener<filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
openSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
singleSession
false
openSessionInViewFilter
/*
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
dwr
uk.ltd.getahead.dwr.DWRServlet
debug
true
dwr
/dwr/*
struts-cleanup
org.apache.struts2.dispatcher.ActionContextCleanUp
struts
org.apache.struts2.dispatcher.FilterDispatcher
struts-cleanup
/*
struts
/*
[/code]
- 在WEB-INF下创建urlrewrite.xml,代码如下 [code="java"]<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN" "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">
^/bugu/([_a-zA-Z]+[_0-9a-zA-Z-/]*[_0-9a-zA-Z]+)/?$
/bugu/loginMainFormAction?login_account=$1
[/code]
但打开“http://localhost:8080/bugu_web/bugu/test”时出现404错误,错误信息如下:
[code="java"]HTTP Status 404 - /bugu_web/bugu/loginMainFormAction
type Status report
message /bugu_web/bugu/loginMainFormAction
description The requested resource (/bugu_web/bugu/loginMainFormAction) is not available.[/code]
但是,我直接在IE输入地址“http://localhost:8080//bugu_web/bugu/loginMainFormAction?login_account=test”或“http://localhost:8080//bugu_web/bugu/loginMainFormAction”可以正常打开网页