0

This is the html file

<!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>

This is the java servlet

package ronit2;
import javax.servlet.http.*;
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 java servlet class in the src > main > java > (package name folder)

and the html file in the webapp folder . {By default}

when I run the file after clicking submit this page shows up

I have tried several solutions online the servlet is properly mapped and the url and names are also properly written still it shows this page.

HTTP Status 404 – Not Found
Type Status Report


Message The requested resource [/ronit2/subtract] is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/10.0.27

The image of the deployment configuration of the server

Please someone help me I am stuck in this from many days it is giving me so much of mental stress and pain.

I would be thankful to everyone who answers please save me. I have deleted whole eclipse and tomcat and reinstalled still I am unable to execute the code it seems that the problem is appearing out of nothing I want a solution to fix this please someone help me

Ronit Pandey
  • 153
  • 1
  • 8
  • 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, in other words: Use either tomcat 9 or `jakarta.servlet.*` – Olaf Kock May 12 '23 at 13:40

0 Answers0