Question: When the page passes "/servlet/detail? Magid = 520 & categoryid = 205 "to access a servlet. This link looks uncomfortable on the IE address bar and you want to disguise it as another address, for example, if you want to disguise it as/servlet/detail/520_205.html or another URL address, how can this problem be achieved?
[Note: The page connection is not "/servlet/detail/520_205.html
"But"/servlet/detail? Magid = 520 & categoryid = 205 "]
Urlrewrite. xml configuration:
Error code:
<Urlrewrite>
<Rule>
<From>/servlet/detail/(%0-9%%%%%_(%0-9%%%%%.html </from>
<To>/servlet/detail? Magid = $1 & amp; categoryid = $2 </to>
</Rule>
</Urlrewrite>
Many new users think that this configuration can solve the problem above. In fact, the error occurs. In this case, the page can only be accessed through "/servelt/detail/24_42.html". When accessing this address, it will forward to/servlet/detail? Magid = 24 & categoryid = 42. If we use "/servlet/detail? Magid = 24 & categoryid = 42 "won't be overwritten. This is a common problem for beginners.
Correct code:
<Urlrewrite>
<Rule>
<From>/servelt/detail/(%0-9%%%%%_(%0-9%%%%%%.html </from>
<To>/servelt/detail? Magid = $1 & amp; categoryid = $2 </to>
</Rule>
<Outbound-Rule>
<From>/servlet/Detail\? Magid = ([0-9] +) & amp; categoryid = ([0-9] +) </from>
<To>/servlet/detail/zookeeper 2.html </to>
</Outbound-Rule>
</Urlrewrite>
The above configuration basically realizes the problem raised above.
1: through: "/servlet/detail? Magid = 24 & categoryid = 42 ", which must be configured in the <outbound-Rule> label and related information must be configured in <rule>. If there is no configuration in the rule, the related resource information will not be found, with Error 404
2: note the above configuration file: the special symbol "?" In <outbound-Rule> "&" Must be escaped. Otherwise, an error occurs and cannot be rewritten. As shown in the preceding "outbound-Rule> from tag, if"? "appears in the path, Remember to escape the question mark "\?".
3: in JSP, If you directly write <a href = "/servlet/detail? Magid = 24 & categoryid = 42 "/>.
It can only be used inResponse. encodeurl ()OrC: URL in jstl. This is also prone to mistakes.
JSP: Key page code:
<A href = "<C: URL value = '/servlet/detail? Magid = 3934 & categoryid = 3'/> "> jstl C: URL </a> <HR/>
<A href = "<% = response. encodeurl ("/servlet/detail? Magid = 3934 & categoryid = 3 ") %>"> response encodeurl </a>
4: If you want to define multiple from to tags in <outbound-Rule>, only one from to tag can be defined in <outbound-Rule>. This is the conclusion I have tested in the program. Only one from to tag can be defined in the conclusions of a personal test. If this is not the case, please correct me and judge.
5: Through the above urlrewrite. xml configuration, <a href = "Servlet/detail? 44_77.html "> test </a>. That is, it is equivalent to two-way.
In this way, the real address is hidden.
Note the following:
Using the example above JSP's with the code
<A href = "<% = response. encodeurl ("/World. jsp? Country = USA & amp; city = NYC ") %>"> NYC </a>
Will output
<A href = "/World/USA/NYC"> NYC </a>
Or jstl
<A href = "<C: URL value ="/World. jsp? Country =$ {country} & amp; city =$ {city} "/>"> NYC </a>
Will output
<A href = "/World/USA/NYC"> NYC </a>
The link to be converted cannot be directly written in the tag. It must be written in the C: URL or other variables to be parsed by the server so that the link can be re-displayed.
Note: <rule> labels can exist independently. The <outbound-Rule> must be paired with the <rule> label. In addition, the <C: URL> label is required for conversion to the <rule> rule.
From: http://hi.baidu.com/allen_zzw/item/e2d16a539fdf41a2acc857b2