Mapping jsp to url

I have a jsp page userhome.jsp - and it usually takes the form:

userhome.jsp?user=username

 I need to map this jsp to "/username"

 In other words, I need to map 

http://www.mysite.com/userhome.jsp?user=username

to

http://www.mysite.com/username

How do I do that?

Thanks.

here are the steps to follow:

  1. Download urlrewrite-2.6.0.jar file and put it in WEB-INF folder.
  2. Add Filter entry in web.xml

    <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>
    </filter-mapping>

  1. And Add your rewrite Rules in urlrewrite.xml file

If you have any further queries and difficulties on url mapping just follow instructions given in the URl below
URL Mapping for JSP

Will this just redirect from URL1 to URL2? I need both URL1 and URL2 to point to URL2, but with the content contained in URL1.

So if a user goes to URL2, it invokes the content in URL1 - but the web address/url remains URL2

If the user goes to URL1, it re-directs to URL2

Thanks

URL1 = http://www.mysite.com/userhome.jsp?user=username

URL2 = http://www.mysite.com/username

This will do server side redirection.
If you type www.mysite.com/username then userhome.jsp page with argurent userhome.jsp?user=username will be execute in server.
But if you type “userhome.jsp?user=username” in browser it won’t redirect to mysite.com/username.

I need the browser location bar to show www.mysite.com/username - but the content from userhome.jsp?user=username should be displayed, irrespective of whether the user types in www.mysite.com/username or mysite.com/userhome.jsp?user=username in the browser location bar.

Any suggestions?

Thanks.

What you’re doing is “REST” for example

/user/admin

This url will take you to a page where it shows the “admin” user information.

To do this, you need to know how to achieve REST in Java. I’m afraid this will take more than few paragraph to explain. Look up in google “Spring MVC RESTful”.

Can’t I do it with url rewriting? I already do url rewriting
in the .htaccess file to point mysite.com to www.mysite.com - which
points to index.jsp, ie

site.com -> www.site.com -> index.jsp

Now what I need to do is

mysite.com/userhome.jsp?user=username -> mysite.com/username -> Content from mysite.com/userhome.jsp?user=username

Can’t I do this with .htaccess url rewrite or the urlrewrite mentioned above?

Any suggestions?

Thanks