aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) 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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Help me with servlet - mapping" Watch "Help me with servlet - mapping" New topic
Author

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>
<body>
<font size='5' color='blue'>Please Login</font><hr>

<form action='/valid.do' method='post'>
<table>
<tr><td>Name:</td>
<td><input type='text' name='employeeId'></td></tr>
<tr><td>Password:</td>
<td><input type='password' name='password' size='8'></td>
</tr>
</table>
<br>
<input type='submit' value='login'>
</form></body>
</html>

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

My web.xml has the following code:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>logic.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
But when I press submit button in index page, I am getting /valid.do 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
Troy Peter
Greenhorn

Joined: Oct 13, 2005
Posts: 14
Hi Ratna,

I strongly suggest you take out the / in your form action attribute and try again. If you look in you browser url, you'll find 2 slash before valid.do.

Good luck,

Troy.
[ October 14, 2005: Message edited by: Troy Peter ]
Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
I think, you have to start the form action with web context name. If your servlet is in context called web1.. then u have to have action for the form as /web1/valid.do


Rizwan
SCJA, SCJP, SCWCD, SCBCD, SCDJWS.
Bhavna Jharbade
Ranch Hand

Joined: Sep 08, 2005
Posts: 69
hi Ratna
i completely agree with Troy, remove the / from the form action. But i also have a doubt if one can set the url-pattern the way you have done.


SCJP1.4 (86%)
Troy Peter
Greenhorn

Joined: Oct 13, 2005
Posts: 14
Hi all,

Bhavna, setting the url-pattern that way is legal...it simply tells the container to watch for anything with extension .do.

Regards,
Troy.
[ October 15, 2005: Message edited by: Troy Peter ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help me with servlet - mapping