Issue
I know this question has been asked a lot but I tried everything and it's still not working for me, hoping someone can help.
I'm trying to run a servlet page on server with eclipse, keeps showing this error:
Here's my source code:
I've wrote a simple servlet page just to see it running on server:
package main.java.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StationsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public StationsServlet() {
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println("<html>");
writer.println("<body>");
writer.println("Hello");
writer.println("</body></html>");
writer.flush();
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
}
My web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>weather-files-war</display-name>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>stationsServlet</servlet-name>
<servlet-class>main.java.servlet.StationsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>stationsServlet</servlet-name>
<url-pattern>/stations</url-pattern>
</servlet-mapping>
</web-app>
and finally, my folders/modules structure:
- PS: I created a homepage.jsp and it's working properly on server, the problem is when hitting the servlet class.
Solution
I created a new project and a new workspace and just copied modules and classes to the new one and it worked.
I guess it was something to do with eclipse project structure and configurations.
Answered By - Saif Badran
Answer Checked By - David Marino (JavaFixing Volunteer)