This question already has an answer here:
In my jsp if I call <form action="/sampleServlet" method="get" name="form1">
, I get the following exception :
http 404 error--sampleServlet is not found.I set sampleServlet in web.xml file and url-pattern also set to /sampleServlet.
Why I am getting 404 (not found servlet.)?
When you are using URL in HTML, without leading / they are relative to the current URL (ie current page displayed). With leading / they are relative to the website root :
or
will do what you want.
I suggest you to add the context inside the action path dynamically. Example (in JSP) :
With this you will never have to change the path, for example, if you move your file or copy your code, or rename your context!
might help you
servlet configuration
Servlet Code :
JSP code :
you can click on submit button and after you can see servlet out put
Just use action="sampleServlet"
It will work for you.