JAVA
FILE
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.Servlet;
importjavax.servlet.ServletException;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassAssignmentextendsHttpServlet {
protectedvoiddoGet(HttpServletRequestrequest,
HttpServletResponseresponse) throwsServletException,
IOException {
PrintWriterout =response.getWriter();
String n1 = request.getParameter("txt1");
String n2 = request.getParameter("txt2");
String op = request.getParameter("op");
out.println("Welcome
to Servlet......");
if(op.equals("Addition")){
out.println("Answer
is ="+(Integer.parseInt(n1) + Integer.parseInt(n2)));
}
elseif(op.equals("Subtraction")){
out.println("Answer
is ="+(Integer.parseInt(n1) - Integer.parseInt(n2)));
}
elseif(op.equals("multiplication")){
out.println("Answer
is ="+(Integer.parseInt(n1) * Integer.parseInt(n2)));
}
else{
out.println("Answer
is ="+(Integer.parseInt(n1) / Integer.parseInt(n2)));
}
}
}
-----------------------------------------------------------------------
XML FILE
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"id="WebApp_ID"version="3.1">
<display-name>Servlet1</display-name>
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>Assignment</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/Assignment</url-pattern>
</servlet-mapping>
<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>
-----------------------------------------------------------------------
HTML FILE
<html>
<head>
<title>Calculator</title>
</head>
<body>
<formaction="Assignment"method="get"name="frm">
<p>
Enter num1:
<inputname="txt1"type="text"/>
</p>
<p>
Enter num2:
<inputname="txt2"type="text"/>
</p>
<p>
Operator
<selectname="op">
<optionvalue="Addition">Addition</option>
<optionvalue="Subtraction">Subtraction</option>
<optionvalue="multiplication">multiplication</option>
<optionvalue="division">division</option>
</select>
</p>
<p>
<inputtype="submit"value="submit"/>
</p>
</form>
</body>
</html>
Hi
ReplyDeleteI just really wanted to say you have quite an amazing blog here. The way you write your articles makes it so easy for users to resonate. I’ve been looking for a good article about Job attendants when I stumbled on your article and it really brought my search to an end.
I am impressed by the construct of your article. I too am a blogger and I know the kind of work you have to put into an article to make it this amazing. I really do hope you can take a second to check out my website on SCHOLARSHIPS.
Looking for Stay at Home Jobs, review;
Health Worker Job in UK .
Nursing Jobs in Canada