JSP

JSP Projects

JSP Project

What are Scripting elements in JSP?
Previous Home Next

 

Scripting elements enables the coder to insert java code in to the servlets that will be generated from the current JSP page.

There are five different types of scripting elements

Scripting Element           Example
Comment                     <%-- comment --%>
Directive                             <%@ directive %>
Declaration                     <%! declarations %>
Scriptlet                             <% scriplets %>
Expression                     <%= expression %>

Expression:-This element contains the java expressions that returns the value.Expression tag contain any Expression but it should be valid according to java language.
Syntax
<%= Java expression %>
Example
Your hostname : <%=request.getRemoteHost()%>
 Scriplet:-Sciplet can contain number of language statements ,methods ,variables,expressions and declarations.that are valid in scripting language.Scriplets are executed at the request time when the JSP container process the request. Any text, HTML tags, or JSP elements must be write outside the scriptlet
Example:-<%
    // This scriptlet declares and initializes "date"
    java.util.Date date = new java.util.Date();
%>
Declaration:-methods or variables are initialized inside the declaration tag.
Syntax
< %!  Declaration   %>
Example:-
<%!
    Date getDate()
    {
        System.out.println( "In getDate() method" );
        return new Date();
    }
%>


 

Previous Home Next