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

Help me with servlet - mapping

bhilla ratna
Ranch Hand

Joined: Jun 01, 2005
Posts: 59
I am writing a simple web application. I have one JSP and one servlet.

The code in JSP is
<html><head><title>Login Page</title></head>
<font size='5' color='blue'>Please Login</font><hr>

<form action='/' method='post'>
<td><input type='text' name='employeeId'></td></tr>
<td><input type='password' name='password' size='8'></td>
<input type='submit' value='login'>

I have a ActionServlet class.
I want this index page be handled by this ActionServlet.

My web.xml has the following code:
But when I press submit button in index page, I am getting / is not availabel.
How to get rid of this problem?
Please help me.

Ratna bhilla<br />SCJP 1.4, SCBCD 1.3, SCWCD 1.4
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
put a / in front of the URL pattern. Here is what you have.


It should be:


So much trouble in the world -- Bob Marley
Troy Peter

Joined: Oct 13, 2005
Posts: 14
Bosun, so much trouble indeed...

You can't have a slash when using <url-pattern>*.do</url-pattern>.
Rather Ratna should not have a slash in the html form action.

Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
If use struts framework check the strust-config.xml for correct mapping of your servlet.

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Yup, you cannot have a leading '/' when using file extension mapping for url-pattern. Refer to Servlet specification 2.4, SRV.11.2.

You might want to try to include the context path into your html form action attribute, because the client browser interpret '/' as relative to the server root, instead of relative to application.

SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="" target="_blank" rel="nofollow"></a>
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Thanks for pointing that out guys. I never really tried it, so I was not aware. Also, the Book I am using "More servlets and JSP" By Marty Hall on page 285 has servlet mapping that refers to a file extension, and there was a '/' in front of it.

Here is an excerpt from the book.
I agree. Here's the link:
subject: Help me with servlet - mapping
It's not a secret anymore!