I'm trying to set up a dynamic web app using Eclipse Juno and Tomcat 7. My problem is that i can only get my servlet to run if my file structure is
MyProject/Java Rescources/src/(default package)/MyServlet.java
I've read i should avoid using the default package (don't know why) but when i try to use a different package:
MyProject/Java Resources/src/myPackage/MyServlet.java
I get the error message:
HTTP Status 404 - /MyProject/MyServlet The requested resource is not available
Its only a small test project so i can start a new workspace and create the project anew if necessary. I suppose i have to change a path somewhere but i don't know where or how.
I got it working using the following in web.xml
<servlet>
<servlet-name>QNumInput</servlet-name>
<servlet-class>myPackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>QNumInput</servlet-name>
<url-pattern>/QNumInput/QNumReq.do</url-pattern>
</servlet-mapping>
The index.html file calls this with the tag:
<form name="getQNumForm"
action="http://localhost:8080/MyProject/QNumInput/QNumReq.do"
METHOD = "POST">
<B>Enter Question Number 1 to 200</B>
<INPUT TYPE="TEXT" NAME="qNumber">
<INPUT TYPE="SUBMIT" VALUE="Request Question Text">
</form>
It did not work at first so i cleaned the tomcat work directory by right clicking on the server (not sure if this is necessary) It still did not work so i gave up and exited Eclipse. This must have saved the new settings because when i fired up Eclipse again and tried it again it worked ok. Thanks for the help. DG
You will need to make sure your
<servlet-mapping>
and<servlet>
elements in web.xml are correctly set.