My servlet is not working even though the code seems to be correct. where have I gone wrong?
First.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class First extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
int sum;
int x,y;
String a = request.getParameter("num1");
String b = request.getParameter("num2");
x = Integer.parseInt(a);
y = Integer.parseInt(b);
sum = x + y;
out.println("The sum is" + sum);
}
}
}
Test.html
<html>
<head>
<title>Supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="First">
Number1:<input type="text" name="num1" /><br/>
Number2:<input type="text" name="num2" /><br/>
<input type="submit" value="button" />
</form>
</body>
</html>