1

I am unable to execute this hello world servlet I have tried everything it has taken more than 10 hours still I cannot solve this It would be really thankful of anyone who.

This is the html code

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>lifelongterror</title>
</head>
<body>
<header><h1>This is a java web project #1</h1></header>
<form action="subtract" method="get">
<input type="submit">Click to say hello world.<br>
</form>

</body>
</html>
import javax.servlet.annotation.*;
import java.io.*;
@WebServlet( name="subtract" ,urlPatterns={"/subtract"})
 class Serv3 extends HttpServlet{
  static final long serialVersionUID = 3535335;
    public void doGet(HttpServletRequest req, HttpServletResponse res) {
try {
PrintWriter p = res.getWriter();

p.println("hello World");
}catch(IOException e) {e.printStackTrace();}
}}

I have placed the servlet class in src>main>java>package and the html file in webapp (By Default)

This is the deployment configuration in server

Still it is throwing a 404 error and showing this page

Showing this error page

I have tried several things but this won't go I think everything is ok but I cannot understand why this error is coming out of nowhere.

Also it is not a browser problem I have tried this in eclipse internal browser Chrome and Microsoft edge still it is not working.

All answers would be valuable.

Ronit Pandey
  • 153
  • 1
  • 8
  • 1
    Use tomcat9 or jakarta.servlet.* instead of javax.servlet.* – Olaf Kock May 13 '23 at 04:19
  • 1
    According to your first screenshot, Tomcat is not running. – andrewJames May 13 '23 at 13:34
  • Does this answer your question? [Servlet 5.0 JAR throws compile error on javax.servlet.\* but Servlet 4.0 JAR does not](https://stackoverflow.com/questions/64387472/servlet-5-0-jar-throws-compile-error-on-javax-servlet-but-servlet-4-0-jar-does) or [Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"](https://stackoverflow.com/questions/11731377) – Olaf Kock May 15 '23 at 07:27
  • 1
    Also, Please [don't upload text as image](https://meta.stackoverflow.com/a/285557/13447). Consider to use the editor's formatting options, take the [tour] and see [ask]. – Olaf Kock May 15 '23 at 07:28

0 Answers0