Home Tutorial Jquery Calculating square root using JSP & jQuery

 
 

Share on Google+Share on Google+
Calculating square root using JSP & jQuery
Posted on: July 26, 2010 at 12:00 AM
Advertisement
In this tutorial, we will find square root of any number with the help of JSP & jQuery.

Calculating square root using JSP & jQuery

In this tutorial, we will find square root of any number with the help of JSP & jQuery. In this example, we have a JSP file which have jQuery 'javascript' :

index.jsp

<html>
<head>
  <title>Simple jQuery and JSP example</title>
  <script src="jquery-1.4.2.js" type="text/javascript"></script>
  <script src="script.js" type="text/javascript"></script>
</head>
<body>
<form id="form" action="calculate.jsp" method="post">
  Enter number:
  <input id="number" type="text" name="number" />
  <input id="submit" type="submit" value="Calculate Square Root" 
 
name="submit"/>
</form>
<p id="result"></p>
</body>
</html>

script.js

$(document).ready(function() {
  $('#form').submit(function(){
  var number = $('#number').val(); 
  $.ajax({type:"post",url:"calculate.jsp",data:"number=" 
  +number,success:function(msg){$(
'#result').hide(); 
  $("#result").html("<h3>" + msg + "</h3>").fadeIn("slow"); } });
  return false;
});
});

calculate.jsp

<%page language="java" contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int number = 0;
if(request.getParameter("number")==null){
  out.println("Enter a number!");
else {
  
  number = Integer.parseInt(request.getParameter("number"));
  out.println("Square root of "+ number + " is " 
 
+ Math.sqrt(number));
}/font>
%%>

OUTPUT :

Download Source Code

Advertisement

Related Tags for Calculating square root using JSP & jQuery:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 26, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com