Java Server Pages - The scriptlets

January 2017



A JSP scriptlet is a block of Java code contained between the following tags:
<% /* scriptlet */ %>


The Java code (which must of course be valid) present between the <% and %> becomes the body of the _jspService() method when generating the servlet (at least if no directive is indicated).

The scriptlet implicitly has access to many objects. The most widely used objects in scriptlets are:
-The request object: to have the details of the HTTP request (e.g when using forms)
-The out object out to send data to the client browser. For example:

<% String[] phrases = {"John", "Peter", "Thomas", "What are you doing?"};
for (int i=0; i<phrases.length; i++) {
	out.println(phrases[i]);
}
%>

The main objects of JSP scriptlets


Here is the list of implicitly accessible objects from any scriptlet:

Here is the list of implicitly accessible objects from any scriptlet:


ObjetDérivé deDescription
requestjavax.servlet.ServletRequestObjet containing client request
responsejavax.servlet.ServletResponse Object containing the response from the JSP page. This object is used with servlets and is generally not used with JSP, since the HTML is created directly
pageContextjavax.servlet.jsp.PageContextObject that contains information about the server environment
sessionjavax.servlet.http.HttpSessionObject containing the current session
applicationjavax.servlet.ServletContextObject containing the servlet context
outjavax.servlet.jsp.JspWriterObject containing the output stream
configjavax.servlet.ServletConfigObject containing the configuration of the servlet
pagejava.lang.ObjectObject designating the page itself
exceptionjava.lang.ThrowableObject representing an uncaught exception





Original document published on CommentcaMarche.net

Related


Published by deri58. Latest update on March 4, 2013 at 09:49 AM by deri58.
This document, titled "Java Server Pages - The scriptlets," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).