Struts2 Implement URL pseudo static

Source: Internet
Author: User

Struts2, SSH implementation URL pseudo static steps:

Reliance on Jar:urlrewrite-3.2.0.jar

First step: Create a new Urlrewrite.xml file under Web-inf

Step Two: Configure the Web.xml file, note the order of the configuration files, need to precede the struts configuration







</init-param> </filter>


















Step Three: Configure the Urlrewrite.xml file

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

<! DOCTYPE urlrewrite Public "-// urlrewrite 3.2//en"
"Http://" >


<from>^/([a-za-z0-9]+)/([a-za-z0-9]+) \.htm$</from>

<to type= "Forward" >/$1!$</to>



<from>/([a-za-z0-9]+)! ([a-za-z0-9]+) [\.do]$</from>




Note: rule is the URL rewrite rules, from is the displayed address, to is the actual address of the map. Example: <a href= "http://localhost:8080/douwanplay/user/testUrlRewrite.htm" >go</a>, which indicates that the actual request is user!

is an override parameter, its value is one by one corresponding to the regular expression in from, and can be multiple, () in a matching regular expression, at the start of a string of regular expression ^ specified characters, and $ for the specified end (form a bracket--corresponding to a $ parameter)

Outbound-rule is a reverse-rewriting configuration, where the actual dynamic connection is displayed as a static connection mode on the page after it is mapped. Example: <a href= "<c:url value="/user! "/>" >NO</A> the actual page is displayed as user/testurlrewrite.htm. parameter is configured with rule, <c:url/> is <%@ taglib prefix= "C" uri= "Http://"%>


1, with the Struts2 interceptor need to add:

<dispatcher>REQUEST</dispatcher>//Without this page, you cannot use the STRUTS2 label
<dispatcher>FORWARD</dispatcher>//Forwarding must

2, configure the Web.xml, rewrite must be in strtus2 above.

Web.xml Configuration Order



3>urlrewritefilter this must be after sitemesh, otherwise the rewrite page will not be Sitemesh rendered.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.