| 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
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
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>
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
Troy Peter
Greenhorn
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. Regards, Troy.
|
 |
Raghu Shree
Ranch Hand
Joined: Mar 18, 2005
Posts: 143
|
|
Hi, 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="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" 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 '/valid.do' 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="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
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>
|
 |
 |
|
|
subject: Help me with servlet - mapping
|
|
|