The website has been updated, checkout below websites.

https://codingvariable.com/

Sunday, 1 January 2017

Simple Calculator using Servlet

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
Enter num1:
Enter num2:
Operator

12 comments:

  1. Show the output in same page how?

    ReplyDelete
    Replies
    1. You can use include() method of RequestDispatcher.

      Delete
  2. yes where is the output

    ReplyDelete
    Replies
    1. The 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

      Delete
  3. where shown answer??

    ReplyDelete
    Replies
    1. In Servlet Page i.e In Calculator.java

      Delete
  4. How did I got the result please?

    ReplyDelete
    Replies
    1. Checkout my Updated, Detailed E-Book https://shubhamsinghdev.gumroad.com/l/calculatorusingservlet

      Delete
  5. sorry guys i got output by sorting the error.. but i coundn't comment that... it shows html tag not allowed

    ReplyDelete
    Replies
    1. Yes, 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