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

<filter>

<filter-name>urlRewriteFilter</filter-name>

<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>

<init-param>

<param-name>logLevel</param-name>

<param-value>WARN</param-value>

</init-param> </filter>

<filter-mapping>

<filter-name>urlRewriteFilter</filter-name>

<url-pattern>*</url-pattern>

<dispatcher>REQUEST</dispatcher>

<dispatcher>FORWARD</dispatcher>

</filter-mapping>


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

<dispatcher>REQUEST</dispatcher>

<dispatcher>FORWARD</dispatcher>

<dispatcher>INCLUDE</dispatcher>

</filter-mapping>


Step Three: Configure the Urlrewrite.xml file

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

<! DOCTYPE urlrewrite Public "-//tuckey.org//dtd urlrewrite 3.2//en"
"Http://tuckey.org/res/dtds/urlrewrite3.2.dtd" >
<urlrewrite>

<rule>

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

<to type= "Forward" >/$1!$2.do</to>

</rule>

<outbound-rule>

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

<to>/$1/$2.htm</to>

</outbound-rule>

</urlrewrite>

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! Testurlrewrite.do

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!testurlrewrite.do "/>" >NO</A> the actual page is displayed as user/testurlrewrite.htm. parameter is configured with rule, <c:url/> is <%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>







Description

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
<dispatcher>INCLUDE</dispatcher>

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

Web.xml Configuration Order

1>struts-cleanup:

2>sitemesh

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

4>struts2


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: info-contact@alibabacloud.com 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.