Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/articles/java-tutorials/)
-   -   Important JSP tags (http://www.go4expert.com/articles/important-jsp-tags-t4204/)

Sanskruti 7May2007 15:51

Important JSP tags
 
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.
  1. Code: JSP

    <%@page language="java" %>

  2. Code: JSP

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

  3. Code: JSP

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

  4. Code: JSP

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

  5. Code: JSP

    <%@ 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: JSP

<%!

int radius = 7;
double pi = 3.1415;

%>

Example 2

Code: JSP

<%!

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: JSP

<%
    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: JSP

<%!

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

mybestjavascript.com 15Sep2008 17:02

Re: Important JSP tags
 
nice keep it

juresh 18Sep2008 13:09

Re: Important JSP tags
 
Hi

nice points, so useful for me a noob web designer.

thanks


All times are GMT +5.5. The time now is 18:00.