Answer the question
In order to leave comments, you need to log in
How to properly compile and run a servlet (Tomcat)?
An error occurs when trying to start the servlet.
Project structure.
web.xml
web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<welcome-file-list>
<welcome-file>
myPage.html
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>D:\MySite\out\production\MySite\ua\user\project\web\MyServlet.class</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>
package ua.user.project.web;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter wr = response.getWriter();
wr.write("Hallo!!");
}
}
Answer the question
In order to leave comments, you need to log in
Because the servlet-class tag should contain not the absolute path to the class file, but the full class name - ua.user.project.web.MyServlet.
Error in line in web.xml:
D:\MySite\out\production\MySite\ua\user\project\web\MyServlet.class Needed
:
ua.user.project.web.MyServlet
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question