This program shows how you can create simple calculator using Servlet. Here you need to create one home page which will be used take some input from the users like number1, number2 and operator. Once you user fill all required fields and click on submit you need to send their request to Servlet. Here Servlet will process calculate that data based on the operator selected by the users.
calculator.html
<html> <head> <title>Calculator</title> </head>a <body> <form action="calculator" method="get" name="frm"> Enter num1: <input name="txt1" type="text" /> Enter num2: <input name="txt2" type="text" /> Operator <select name="op"> <option value="Addition">Addition</option> <option value="Subtraction">Subtraction</option> <option value="multiplication">multiplication</option> <option value="division">division</option> </select> <input type="submit" value="submit" /> </form> </body> </html>
calculator.java
Checkout https://codingvariable.com/ for full-fledge code including calculator.java
https://codingvariable.com/simple-calculator-using-servlet/
Output
Calculator
good
ReplyDeleteThank You
DeleteShow the output in same page how?
ReplyDeleteYou can use include() method of RequestDispatcher.
Deleteyes where is the output
ReplyDeleteThe output will be in displayed Servlet Page, checkout my E-Book which shows the detailed and more personalized view of output https://shubhamsinghdev.gumroad.com/l/calculatorusingservlet
Deletewhere shown answer??
ReplyDeleteIn Servlet Page i.e In Calculator.java
DeleteHow did I got the result please?
ReplyDeleteCheckout my Updated, Detailed E-Book https://shubhamsinghdev.gumroad.com/l/calculatorusingservlet
Deletesorry guys i got output by sorting the error.. but i coundn't comment that... it shows html tag not allowed
ReplyDeleteYes, to protect from XSS Injection I have disabled html tags, but I will find another way to do so that you and others can publish their output. Thanks
Delete