Introduction of Scripting Elements

Introduction of Scripting Elements: JSP scripting elements are used to create and access objects, define methods, and manage the flow of control. Since one of the goals of JSP technology is to separate static template data from the code needed to dynamically generate content, very sparing use of JSP scripting is recommended. Much of the work that requires the use of scripts can be eliminated by using custom tags

JSP technology allows a container to support any scripting language that can call Java objects. If you wish to use a scripting language other than the default, java, you must specify it in a page directive at the beginning of a JSP page:

<%@ page language=”scripting language” %>

 

Since scripting elements are converted to programming language statements in the JSP page’s servlet class, you must import any classes and packages used by a JSP page. If the page language is java, you import a class or package with the page directive:

<%@ page import=”packagename.*, fully_qualified_classname” %>

 

Syntax of JSP scripting language-

<%

 

//java  codes

 

%>

JSP Engine places these code in the _jspService() method.

 

Variables available to the JSP Scriptlets are: request represents the clients request and is a subclass of HttpServletRequest.

These variables are used to retrieve the data submitted along the request.

Example:

<%

 

//java codes

 

String endusers=null;

userName=request.getParameter(“endusers”);

 

%>

Leave a Reply

Your email address will not be published. Required fields are marked *