Write a web application using servlet to compute an area of a circle. get the radius from the client. write necessary web.xml file.
Answers
Answered by
2
JSP Page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<form action="Process" method="get">
<input type="text" name="rad"/>
<input type="submit" value="Area” name="action"/>
</form>
<br/>
<hr/>
<p>The result is :<%=request.getAttribute("result") %></p>
</body>
</html>
Servlet Code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
int op1=Integer.parseInt((String)request.getAttribute("rad"));
int result=3.14*rad*rad;
request.setAttribute("result", new Integer(result));
RequestDispatcher dispatcher=request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
return;
}
AJT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<form action="Process" method="get">
<input type="text" name="rad"/>
<input type="submit" value="Area” name="action"/>
</form>
<br/>
<hr/>
<p>The result is :<%=request.getAttribute("result") %></p>
</body>
</html>
Servlet Code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
int op1=Integer.parseInt((String)request.getAttribute("rad"));
int result=3.14*rad*rad;
request.setAttribute("result", new Integer(result));
RequestDispatcher dispatcher=request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
return;
}
AJT
Similar questions
Geography,
8 months ago
Social Sciences,
8 months ago
Computer Science,
1 year ago
Economy,
1 year ago
History,
1 year ago