This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • 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.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put a / in front of the URL pattern. Here is what you have.

<url-pattern>*.do</url-pattern>


It should be:

<url-pattern>/*.do</url-pattern>
 
Troy Peter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Troy.
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If use struts framework check the strust-config.xml for correct mapping of your servlet.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 '/valid.do' as relative to the server root, instead of relative to application.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
<servlet-mapping>
<servlet-name>BashMS</servlet-name>
<url-pattern>/*.asp</url-pattern>
</servlet-mapping>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic