Issue
I'm new to jsp. When i am running jsp file in netbeans and submit http 404 error coming.
This is the from header that i used,
<form method="POST" action="/test.java">
My file hierachy in the netbeans is,
Test
Web Pages
index.jsp
Source Packages
<default package>
test.java
The link that I gave to the action is correct or wrong?
I'm using jdk 7
Solution
No, what you are doing is wrong. I guess you want to submit this form to a Servlet(test.java).
First you have to make sure that test.java (btw this is not a proper convention in java for a class name, it should start with an uppercase letter) is actually a servlet by extending the HttpServlet class, and implementing the required methods (doGet()
and/or doPost()
...). More Info Here
Then you have to map this Servlet in the web.xml.
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>test.java</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
And then submit the form to the url-pattern
of the servlet assigned above. In this example your form should look like this:
<form method="POST" action="/Test">
Note: You can use the IDE's servlet wizard to automate this functionality, but Its always better to know also how things work internally.
You can check also https://stackoverflow.com/tags/servlets/info to see how servlets work
Answered By - MaVRoSCy
Answer Checked By - Robin (JavaFixing Admin)