I am starting with learning JSP and servlets and while setup i followed all the steps correctly and added the tomcat server then created a servlet in a new package for a dynamic web project. But whenever I select the file and run it on server this link pops up http://localhost:8080/Project/WEB-INF/classes/myPackage/MyServlet.java
which gives the error "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."I have no idea what to do and have tried a lot to search on everywhere but can't seem to find anything.It should be directing to http://localhost:8080/Project/MyServlet
and when i manually type the url then it works but it never reaches there on its own
this is the web.xml i have :
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" id="WebApp_ID" version="6.0"><display-name>Project</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.jsp</welcome-file><welcome-file>default.htm</welcome-file></welcome-file-list><servlet><description></description><display-name>MyServlet</display-name><servlet-name>MyServlet</servlet-name><servlet-class>myPackage.MyServlet</servlet-class></servlet><servlet-mapping><servlet-name>MyServlet</servlet-name><url-pattern>/MyServlet</url-pattern></servlet-mapping></web-app>
this is the file :
package myPackage;import jakarta.servlet.ServletException;import jakarta.servlet.annotation.WebServlet;import jakarta.servlet.http.HttpServlet;import jakarta.servlet.http.HttpServletRequest;import jakarta.servlet.http.HttpServletResponse;import java.io.IOException;/** * Servlet implementation class MyServlet */public class MyServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public MyServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); }}
please help me with this
I just want it to direct to the correct URl http://localhost:8080/Project/MyServlet
. I have no idea why i this is happening. I would really appreciate if someone helps me out.