Contact Us
   
   
 
   
   
 
     
 
 
JSP Tutorial
 
Book Must Read
 
 

JSP Variables

 
 
Print   Email
 
     
 

If you familiar with other programming language, java too has data type variable to identify what data to belongs. This variable stores information of data, and differentiate with others.  E.g.
String, int, byte, long, float, double, boolean

Declare a variable

Declaration of variable in JSP is storing information of data. We need to define data’s type what is this. It may be a string, may be a int (integer), or float

1. String variable Example in JSP

jspString.jspOutput

 
<%@ page  language="java" errorPage="" %>
<%
String stVariable="this is defining String variable";
%>

<html>
<body>
String variable having value : <%=stVariable%>
</body>
</html>

2. Int variable Example in JSP

int can only having numeric values e.g 1,2,3,5

jspInt.jspOutput

 
<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%
int iVariable=5;
%>

<html>
<body>
int variable having value : <%=iVariable%>
</body>
</html>

3. Long variable is same as int variable just long can store more bytes than int.

4. float variable Example in JSP

float variable can be having decimal numbers. E.g 5.6 ,23.455

jspFloat.jspOutput

 
<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%
float fVariable=567.345f;
%>

<html>
<body>
float variable having value : <%=fVariable%>
</body>
</html>

When you work on float variable don’t forget to add f character float fVariable=567.345f, otherwise it will get error of “Type mismatch: cannot convert from double to float”

5. double variable Example in JSP
This is same as float variable; it can store more bytes than float variable. In double we don’t need to put f character

6. Boolean variable Example in JSP

This is useful when we need to check condition. Let’s check in example

jspBoolean.jspOutput

 
<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%
boolean checkCondition=false;
%>

<html>
<body>
    <%
    if(checkCondition==true)
    {
      out.print("This condition is true");
    }
    else
    {
      out.print("This condition is false");
    }
    %>
</body>
</html>

Output this jsp page “This condition is false”

 

 

 

 
If You Like this Article, share this

 
 
     
   
  View Forum Post  
 
Optimization of SQL queries for better performance
Example of Between in mysql
Example of sorting in mysql table
Example of join in mysql
Example of subquery in mysql
union join in mysql with example
error too many connection in mysql
calculate second highest salary
How to use select queries with array in mysql
Radio button pre selected in struts
Exception in thread "main" java.lang.NoClassDefFoundError
tree view in jsp
SSL implement in tomcat and java certificate
WARNING: Internal error flushing the buffer in release()
DynaForm validation problem in struts not working
Accessing JavaBean in servlet or servlet in javaBean.
 
     
     
   
     
     
     
 
  Privacy Policy