1

How do I redirect a user in my dynamic web project so that when he opens localhost:8080/pageName he actually gets somepage.html opened which is inside my WebContent folder? What do I write in web.xml to achieve that?

I want user to enter localhost:8080/pageName but actually see localhost:8080/somepage.html

Olotiar
  • 3,225
  • 1
  • 18
  • 37

1 Answers1

0

You could use a filter. This url shows how to install a jar, and modify your web.xml: http://tuckey.org/urlrewrite/

Your rewrite file would look like this:

<?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>
        <name>pageName Redirect</name>
        <from>^/pageName$</from>
        <to>/somepage.html</to>
    </rule>
</urlrewrite>

Edit:

My example does not change the URL in the users browser. It's form is helpful when you want more than one URL to show the same content.

If you want to change the URL, make this change to the code above:

        <to type="redirect">/somepage.html</to>

Instead of sending the users browser content to display, this sends a message to the browser that the page has moved, and it should, transparently modify the browsers URL, and then load that page.

Difference between JSP forward and redirect

Community
  • 1
  • 1
Brian Maltzan
  • 1,327
  • 10
  • 12