Contact Us
   
   
 
   
   
 
     
 
 
JSP Tutorial
 
 
 

JSP Variables

AddThis Social Bookmark Button          AddThis Feed Button
 
 
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

 
 
     
   
  Host 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.
 
 
>> Tomcat Clustering
Clustering is technique to improve the performance, high scalability, and failover of web-server or any servers. Number of users increase with increase load on the servers
 
     
 
>> Implementation of tomcat clustering
Simple steps to do tomcat clustering with code
 
     
 
>> Tomcat Installation & Configuration
Tomcat installation on windows, environment system variables setting in Visual mode for easy installation and configuration of web.xml other servlet invoker setting
 
     
 
>> Apache Tomcat integration with mod_jk
Integrate Apache web server with tomcat web server with mod_jk
 
     
 
>> Java Servlet Examples
Tomcat installation on windows, environment system variables setting in Visual mode for easy installation and configuration of web.xml other servlet invoker setting
 
     
 
>> Apache installation
Apache installation on windows and linux
 
     
 
>> Mysql Installation
Mysql installation on windows, Port setting,installing mysql tools query browser, connecting to database,creating database, creating tables
 
     
 
>> Apache PHP MySql integration
 
 
     
     
     
     
     
 
Powered by Web4Bharat   Privacy Policy