I've been trying to find the solution for my problem since a week but couldn't succeed. There may be more than 100 same questions of this type, but they not helping me at all. Pls if anyone can explain what exactly is URL mapping and how it is done?
I'm using tomcat 7 and eclipse java EE. my jsp file is running properly but when I click submit the error appears. I have tried almost everthing. pls let me know what mistake I'm making.
here's my jsp code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="/calculator/calc">
<input type="text" name="n1"><br>
<input type="text" name="n2"><br>
<input type="submit">
</form>
</body>
</html>
Servlet code:
public class calc extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res) throws IOException
{
res.setContentType("text/jsp");
PrintWriter pw=res.getWriter();
String s1=req.getParameter("n1");
String s2=req.getParameter("n2");
int a=Integer.parseInt(s1);
int b=Integer.parseInt(s2);
pw.println(a+b);
}
}
And web.xml
<?xml version="1.0" encoding="UTF-8"?>
<display-name>calculator</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>