This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
On the login.jsp of my humble app, there is a hyperlink for new users who like to register. The purpose is to send them to register.jsp. Here it is:
If i remove slash, i get a blank page. If i keep slash i get a straightforward http 404 "/ActionServlet not found".
But i am not able to see the page when i click on the link. I am pretty sure that there is some problem with the mapping in web.xml but since i am new to J2EE i do not know tricks of the trade. Here is the web.xml
This works just fine. It does take me to the servlet when i click on the button present.
But on the very same page if i click on hyperlink, all i see is a blank page. I know there are some conceptual flaws here related tomapping. I tried tweaking web.xml (i have heard that's not recommended) too many times but in vain. At times i got downright http 404, at other times, milder versions like the blank page. I am assuming without slash (before the servlet name) is least incorrect.
Lastly, i feel the control does not come to servlet. Put some lines in doPost() and tried to print but there was a blank page. Here is what i see in the browser.
Bear Bibeault wrote:You need to prefix the context path to the servlet path in the action URL.
Thanks. That looks helpful. Any chances of slight elaboration. Even a redirection to some other similar post will be helpful. Also, why is there no such need of prefixing with contextpath in case of <form action="<ServletName>?<parameters>">. As i mentioned, it works just fine when i click the submit button. If the question is too basic and directly relates to J2EE fundamentals, please redirect to some helpful link.
Ok thanks for the insight Bear. If I understand correctly, i should totally do away with <a href> tags in my jsp and go for <c:url> instead. Off course, context path should be obtained. I think if i go by <a> tags i will still need some scriptlet code to get the same. So <c:url> wins there too. Please correct if needed. Thanks for the guidance.
The error is resolved. It was not about addressing or anything like that. I was missing the very basic fact that hyperlinks will always result in calling of doGet() (which in my servlet is empty, since all my JSPs explicitly submit with post method). I have overridden it now and put placed doPost() inside it.
In hindsight, i should have got this looking at the blank page. Nonetheless, i am introduced to <c:url> and cleaner JSPs. Thanks for your time.