Saturday, June 7, 2014

Notes On JSP

Well I have been using JSP for years and I below was my notes when I was a novice. Oh how they seemed silly now though they are correct.
Some old code I used as a novice

<% 
if(userProfile==null)
out.println(request.getParameter("Firstname")+" "+request.getParameter("surname"));
else out.println(userProfile.getFirstName()+" "+userProfile.getLastName());
%>


Special JSP tags

A JSP page consists of three kinds of elements, each with its own special markup tag
that’s similar to HTML:
Scriptlets—Java code executed when the page is loaded. Each of these state-
ments is surrounded by <%and %>tags.
Expressions—Java expressions that are evaluated, producing output displayed on
the page. These are surrounded by <%= and %>tags.
Declarations—Statements to create instance variables and handle other setup tasks

required in the presentation of the page. These are surrounded by  <%! and %>tags.

Servlet objects used in Expressions

There are several servlet objects you can refer to in expressions and other elements of a
JSP page using the following variable names:
 out —The servlet output stream
 request—The HTTP servlet request
 response —The HTTP servlet responses
session—The current HTTP session
application —The servlet context used to communicate with the web server
config —The servlet configuration object used to see how the servlet was initialized

No comments:

Post a Comment