Total members 11894 |It is currently Thu Nov 21, 2024 7:46 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





There are four types of JSP tags, which are important and often required.

1. Directives

These types of tags are used primarily to import packages. Altenatively you can also use these tags to define error handling pages and for session information of JSP page.

Code:
<%@page language="java" %>

Code:
<%@page language="java" session="true" %>

Code:
<%@page language="java" session="true" errorPage="error.jsp"  %>

Code:
<%@page language="java" import="java.sql.*, java.util.*" %>

Code:
<%@ include file="/title.jsp"%>


2. Declarations


JSP declarations starts with '<%!' and ends with '%>'. In this you can make declarions such as int i = 1, double pi = 3.1415 etc. If needed, you can also write Java code inside declarations.
Example 1
Code:
<%!

int radius = 7;
double pi = 3.1415;

%>


Example 2
Code:
<%!

double radius = 7;
double pi = 3.1415;

double area()
{
    return pi*radius*radius;
}

%>

3. Scriptlets
JSP Scriptlets starts with '<%' and ends with '%>'. This is where the important Java code for JSP page is written.
Example :
Code:
<%
    String id, name, dob, email, address;
               
    id = request.getParameter("id");
    name = request.getParameter("name");
    dob = request.getParameter("dob");
    email = request.getParameter("email");
    address = request.getParameter("address");

    sessionEJB.addClient(id, name, dob, email, address);
%>


request, response, session and out are the variables available in scriptlets.

4. Expressions

JSP expressions starts with '<%=' and ends with '%>'. If you want to show some value, you need to put it in between these tags.
Example:
Code:
<%!

double radius = 7;
double pi = 22/7;

double area()
{
    return pi*radius*radius;
}

%>

<html>
  <body>
    Area of circle is <%= area() %>
</body>
</html


You will see the output:
Code:
Area of circle is 147.0




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Important JSP tags
 Important : Read before you post .     -  
 Usage of the CSS property !important     -  
 Java Important interview questions     -  
 Get the important variables of random forest classifier     -  
 web hosting sites free check out important useful     -  
 HTML Tags -2     -  
 help in meta tags     -  
 PHP Start and End Tags     -  
 Examples of heading tags     -  
 H1 H2 H3 H4 H4 H5 H6 heading html tags     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com