• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me with servlet - mapping

 
bhilla ratna
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Troy Peter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Troy Peter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic