How can i implement the calculator programe in jsp code

How can i implement the calculator programe in jsp code

Please send code for the calculator using jsp technologies please guidelines to me.

View Answers

September 6, 2012 at 5:07 PM

Here is a simple jsp calculator code that accepts two numbers from the user and allow to select the operator they want to use. After calculating the result, it will display it on the browser.

<html>
<head>
<title>calculator program in jsp</title>
<script>
function checkValue(){
var msg = "";
if (f1.operand1.value == "" || f1.operand2.value == "")
msg += "Operands missing\n";
if (f1.op.selectedIndex == 3 && f1.operand2.value == 0)
msg += "Division by zero";
if (msg.length > 0){
alert(msg);
return false;
} else
return true;
}
</script>
</head>

<body>

<%
String str = "0",op2 = "0";
int result = 0;
String op = "+";
char opchar = op.charAt(0);
if (request.getParameter("op") != null){
op = request.getParameter("op");
opchar = op.charAt(0);
str = request.getParameter("operand1");
op2 = request.getParameter("operand2");
switch(opchar){
case '0': result = Integer.parseInt(str) + Integer.parseInt(op2);
break;
case '1': result = Integer.parseInt(str) - Integer.parseInt(op2);
break;
case '2': result = Integer.parseInt(str) * Integer.parseInt(op2);
break;
case '3': result = Integer.parseInt(str) / Integer.parseInt(op2);
break;
case '4': result = Integer.parseInt(str) % Integer.parseInt(op2);
break;
}
}
%>
<center>

<h2>Simple calculator program in jsp</h2>
<form method ="get" name ="f1" onsubmit = "return checkValue()">
<input type ="text" size ="20" name ="operand1" value = <%= str %> />

<select name = op size = 1>
<option value = "0" <% if (opchar == '0') out.print("selected"); %> >+</option>
<option value = "1" <% if (opchar == '1') out.print("selected"); %> >-</option>
<option value = "2" <% if (opchar == '2') out.print("selected"); %> >*</option>
<option value = "3" <% if (opchar == '3') out.print("selected"); %> >/</option>
<option value = "4" <% if (opchar == '4') out.print("selected"); %> >/</option>
</select>

<input type ="text" size="20" name ="operand2" value = <%= op2 %> />
<p>
<input type = submit value = Calculate />

Result = <%= result + "" %>
</form>

</body>

</html>









Related Tutorials/Questions & Answers:
How can i implement the calculator programe in jsp code
How can i implement the calculator programe in jsp code  Please send code for the calculator using jsp technologies please guidelines to me.   Here is a simple jsp calculator code that accepts two numbers from the user
code to enter values in multiple textfields throught 10 buttons (0-9) (as if a calculator programe)
code to enter values in multiple textfields throught 10 buttons (0-9) (as if a calculator programe)  how can i enter values in two different textfield's through 10 different buttons.?? as we saw a online calculator type
Advertisements
I want code below mention programe
I want code below mention programe  Create a web application using any technology that accepts a keyword and displays 10 relevant tweets from Twitter in real-time for that keyword
how can i simplify my java code
how can i simplify my java code  /* Create a program that prompts... Scanner (System.in); String pass=""; int c = 1; int code=0... c=0;int f=0;int i=0; int counter=0; int starter=0; int cot=1
How can i pass the valus from a JSP to the action class???
How can i pass the valus from a JSP to the action class???  hewllo wevryone... can anyone help me with how i can pass the value of menuId in my JSP and pass it in the action class
How i can send mail by using jsp.............. - JavaMail
How i can send mail by using JSP  Hi, will you please tell me how i can send mail by using jsp. Tell me in detail. Thanks!  Example and JSP Code for sending mailSee the give link for JSP coding, that will allow you
how can i connected jsp wih mysql - Java Beginners
how can i connected jsp wih mysql  i have a code jsp file... not exist i have a tomcat 4.0,mysql 5.0, and jdk 1.4 plz any one help me how to connect this and how can i use it plz help me its very urgent plz send my
How can I get the full URL with the attached parameters? - JSP-Servlet
How can I get the full URL with the attached parameters?  Hi, I'm trying to figure out how to get the current url and use it in my jsp page. I...:8080/MesEduSchoolsProject/displayMenu.jsp How can I get the full URL with the attached parameters
How Can I get ArrayList of Data from jsp with ajax request
How Can I get ArrayList of Data from jsp with ajax request  Hi, I retereved 5 Employee Record of Data from Struts Action class to jsp with ajax response. But I don't how how can reterve this dynamic 5 employee records
In JSP page, inside a javascript function, can I place a java code using scriptlet tag?
In JSP page, inside a javascript function, can I place a java code using...() in jsp page. In a separate java file, in a method checkListValue(), I am doing... to checkListValue() method using scriptlet tag. My doubt here is, can I call the method
Design and Implement GPA Calculator
Design and Implement GPA Calculator  Once the user clicks... the following code snippet, may this will be helpful for you. import javax.swing.... Calculator"); //frame.setLayout(new BorderLayout()); frame.setLayout
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...;ZHTYPE (Just Logical) Please tell me how can i see this output? Code... with this code is true but I want add ZHTYPE at the end of each line + XTSM/XTS please
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...;ZHTYPE (Just Logical) Please tell me how can i see this output? Code... This output with this code is true but I want add ZHTYPE at the end of each line
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt....";, "root", "root"); Statement st=con.createStatement(); int i
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt....";, "root", "root"); Statement st=con.createStatement(); int i
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.  I am using postgresql-8.4.4-1... netbeans-6.1-ml-windows.How can I set up connection to database? Please help me
how to implement ajax in struts2 to operate on selectbox in jsp
how to implement ajax in struts2 to operate on selectbox in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes like </s:form>` ` now i want that when i select a district
How to implement session variables - JSP-Servlet
How to implement session variables  Hi, I have a servlet which gets..._num in the Jsp page (y). How should i do it? I'm trying using... print it. Do I need to add any path like (@servlet) because how the jsp know
how i can add an horizontal scrollbar at my PdfAnnotation ? - JSP-Servlet
how i can add an horizontal scrollbar at my PdfAnnotation ?  How to add the an horizontal scrollbar at my PdfAnnotation ? for example document d=new document(0. document.open
Can i write JavaScript code in AjaxResponse Code ?
Can i write JavaScript code in AjaxResponse Code ?  Hai Every Dynamic's We can't write JavaScript code in Ajax Response Code.Why because it takes...'s not working.rather than that i try to created on innerHtml document. here
I need jsp code for how to write text field value into property file.
I need jsp code for how to write text field value into property file.  Hi , I need to set the text field value into property file using jsp code. Example : Username : Valar , I have entered the value "Valar" in the text field
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/bank.shtml
i need the source code to generate id in jsp
i need the source code to generate id in jsp  hai,i need the source code for generate id...which is i need to generate the new id from the maximum... of generate ids each should have some range...plz give the source code in jsp with ms
User Registration Form Using JSP(JspBeans) after that how i can insert in database
User Registration Form Using JSP(JspBeans) after that how i can insert in database   User Registration Form Using JSP(JspBeans) after that how i can insert in database
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
Implement an interface in a JSP
Implement an interface in a JSP  Can we implement an interface in a JSP?   
My Base Class is Changing every time in my code. How I can overcome this?
My Base Class is Changing every time in my code. How I can overcome this?  I have had the below question asked in interview, i'm curious to learn the answer. I have a base class, 'GeneratorBaseClass' that is extended
Calculator - JSP-Servlet
Calculator  Dear Deepak Sir, Calculator program is avilable in Jsp... calculator program in jsp function checkValue(){ var msg...; } Simple calculator program in jsp /> >
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?  this is count record code...;   The given code count the number of rows in a database table. <
how can i use one dbase conection in serveral pages - JSP-Servlet
how can i use one dbase conection in serveral pages  Hi! Thanks for sending code... But my actual requirement is In my project i am writing dbase connections many times whereever i need in several pages. How can I avoid
can i know the error in this code... am unable to run this code
can i know the error in this code... am unable to run this code  ...}; int n=arr.lenght; System.out.println("length of array:"+n); for(int i=0;i System.out.println(arr[i]); } }   You have used incorrect symbol in your
how should i can solve
how should i can solve  Web based program - Input - Person's contact details with Passport Number as Unique Key. Save data in to oracle / MySQL. Output - List of Persons saved in the database. Technology to be used - JSP
can i remopve a jsp web page - JSP-Interview Questions
can i remopve a jsp web page  Dear, I ask you a question BUT you do noit answer me: My question Can I remove .jsp and the program still working because it generates .class file. Regards
How to implement ajax in struts2 to operate on select box in jsp
How to implement ajax in struts2 to operate on select box in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes...:select> </s:form> now i want that when i select a district
what is cloud computing? any how we can implement?
what is cloud computing? any how we can implement?  what is cloud computing? any how we can implement
Implement method in Jsp - JSP-Interview Questions
Implement method in Jsp   Hi Friends, where should we implement methods in jsp(In webApplication... ( or )   Hi I am sending a link where u can find lots
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting... the code .My databse is Mysql 5.0 . I would be pleased by any insight you may
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting... the code .My databse is Mysql 5.0 . I would be pleased by any insight you may
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want...("a"); x.click(); </script> So it's click on an element witch one Id's is "a", but I want that it make mouseup in this element. How can I do it, because if I write
Java code to implement MULTIPATH INHERITANCE
Java code to implement MULTIPATH INHERITANCE  HI, I am new to java programming. I want to implement multipath inheritance in one java program... Please write code for above example to implement both
how to execute this code - JSP-Servlet
how to execute this code  hi guys can any help me in executing this bank application http://www.roseindia.net/jsp/bank.shtml, i need to use any database plz tell me step-to-step procedure for executing this,i need to create
How can I learn Java?
How can I learn Java?  Hi, I have just completed a course in HTML and C programming language. I have some programming experience in visual basic... programming. How can I learn Java? in shortest possible time. I mean I just want to begin
conert java code to jsp... plz imm i wan...
conert java code to jsp... plz imm i wan...  how to convert this java code into jsp?? Java| Frameworks| Databases| Technology| Development| Build... Application Currency Format Example This Example shows you how to format
How i write a function/method in jsp?
How i write a function/method in jsp?  How write the function/method in jsp? Using that method i can retrieve the value coming from database. give me example plz. Actually i want to show the list of user detail
how can i create a discussion forum?
how can i create a discussion forum?  how can i create a discussion forum for my e- mentoring site for women which can be used by a registered user only. i am using jsp and servlets and i am working with netbeans 6.8.
can i Execute PHP code inside python script?
can i Execute PHP code inside python script?    can i Execute PHP code inside python script

Ads