File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Web.xml Question - Map Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Web.xml Question - Map Servlet" Watch "Web.xml Question - Map Servlet" New topic

Web.xml Question - Map Servlet

Jason Stortz
Ranch Hand

Joined: Jan 11, 2001
Posts: 68
I would like to map a name the user can type into the address bar to take a specific action.
For instance, I have the following servlet tag:
So, when the user types in:
it executes the specified controller. Now, is there any way to make ANOTHER mapping that will let the user type in:
and have it execute like this:
A.k.a., I want my landing page to be my servlet, but I want it automatically called with a parameter.
Any mapping guru's out there got any tricks for me?
Jason Stortz
Ranch Hand

Joined: Jan 11, 2001
Posts: 68
A simpler way to say this is I want type
and see the result of
Thanks guys and gals,
Jignesh Malavia
Ranch Hand

Joined: May 18, 2001
Posts: 81
One of the simplest ways is to create a Filter and map it to <url-pattern>/</url-pattern>. This filter will be invoked when you use http://mysite/mycontext. Within the filter you can
either use a Query String as getRequestDispatcher(/servlet/myServlet?someKey=someValue)
or use an HttpServletRequestWrapper that returns someValue for someKey
and then forward the request to myservlet.
As a bonus, you dont have to hardcode the values someKey=someValue in the filter code. You can pass as many of them as required as init-parameters in web.xml
I agree. Here's the link:
subject: Web.xml Question - Map Servlet
It's not a secret anymore!