• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me with servlet - mapping

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If use struts framework check the strust-config.xml for correct mapping of your servlet.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
reply
    Bookmark Topic Watch Topic
  • New Topic