Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I have a servlet (TodayServlet) created in eclipse but when I run it on Tomcat server it's leading to a wrong url and it's showing "HTTP Status 404 - Not Found" error. Please how can I resolve this issue? This is the wrong URL that it's leading to -
Java
http://localhost:9999/webdemo/WEB-INF/classes/servlets/TodayServlet.java

but when I changed it to this url -
Java
http://localhost:9999/webdemo/today
it works. Why can't Tomcat pick the right url? I am using Tomacat 10.0.4 version. Thanks for any help.

What I have tried:

package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/today")
public class TodayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String now =  LocalDateTime.now().toString();
		PrintWriter pw =  response.getWriter();
		pw.println("<h1 style='color:blue'>" + now + "</h1>");
	}
}
Posted
Updated 25-Mar-22 23:14pm
v2
Comments
Richard Deeming 26-Apr-21 5:12am    
The working URL seems to match the URL specified in the WebServlet line. What is leading you to the incorrect URL?
UT7 26-Apr-21 11:29am    
@Richard Deeming, thanks for your response. It's Tomcat that is leading me to the wrong URL. I ran my servlet from Eclipse using the Tomcat server and it directs/leads me to the wrong URL.

1 solution

Degrade your tomcat to version 9.. .It works for me.
 
Share this answer
 
Comments
UT7 26-Mar-22 5:16am    
@Member 15579602 - Yeah, I figured it out, thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900