Reputation: 11
I got a servlet, which I'm trying to get to through a hyperlink.
I checked the Servlet's folder availability by a hyperlink to JSP file on that folder.
I also checked the Servlet itself when asking it on the hyperlink with the .java
extension, and I got
the code of that Servlet on the browser.
When I'm trying to connect to that Servlet either to doGet
or doPost
, I'm getting a 404 HTTP error,
the resource is not available.
Web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>controllers.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/controllers</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/views/welcomePage.jsp</welcome-file>
</welcome-file-list>
</web-app>
What is wrong?
Upvotes: 1
Views: 77
Reputation: 2738
As you post in your question
I also checked the Servlet itself when asking it on the hyperlink with the .java extension
I think you are putting the servlet class file in a folder under your web folder and that is why you can access trough the url.
project
src
web
controllers
TestServlet.java
page.jsp
WEB-INF
classes
As opposed of the jsp files the servlet classes must be in the WEB-INF/classes folder (the .class file not the .java file), and the source code of your class must be in the src
folder of your project under the package controllers so:
project
src
controllers
TestServlet.java
web
page.jsp
WEB-INF
classes
controllers
TestServlet.class
If you're using eclipse, netbeans or other IDE when you put your java class in the source folder it automatically put the .class in the WEB-INF/classes folder.
Upvotes: 1
Reputation: 1889
You map your servlet to the URL pattern /controllers - so your post should go to http://localhostOrWhatever/maybeYourWebAppDirectoryDependingOnSetup/controllers
Upvotes: 0