Download presentation
Presentation is loading. Please wait.
Published byHester Burke Modified over 8 years ago
1
JSP Java Server Pages
2
<% String visitor = request.getParameter( “name” ); if ( visitor == null ) visitor = “World”; %> Hello, !
3
Elements of JSP ● directives ● scripts ● components ● all created through tags or special notations
4
Directives or page, include
5
include Directive ● ● textual inclusion ● semantics same as #include in C++ ● file attribute can be a relative or absolute path ● supports unlimited nesting
6
page Directive ● ● attributes: – info – description – session – does the page support sessions or not – import – external classes used by scriplets on this page
7
session Attribute ● session=”true” – this is the default – page supports sessions ● session=”false” – must be set explicitly – can improve performance for pages that don't need sessions
8
import Attribute ● works like the import statement in a Java program ● can specify multiple classes/packages by separating with commas ● import=”abc.class1” – imports a single class ● import=”xyz.*” – imports an entire package ● java.lang, javax.servlet, javax.servlet.http, and javax.servlet.jsp are imported by default
9
Scripts ● declarations –... – ● expressions –... – ● scriptlets –... –
10
Declartions ● variable declartions become instance variables of the servlet class into which the JSP is translated ● method declarations become methods of the same servlet class ● both are accessible throughout the remainder of the page
11
Special Methods ● public void jspInit() - initialization method called after the servlet is constructed but before the first request processed ● public void jspDestroy() - called after the last request is processed but before the servlet is destroyed
12
Expression ● the value of the expression is converted to a string and inserted into the output stream where it appears in the JSP
13
Scriptlet ● arbitrary Java code inserted into the doGet/Post method at the point where it appears in the JSP ● does not generate any output in the output stream unless explicitly told to do so
14
Implicit Objects ● available to all scriptlets ● JspWriter out – output stream for the response ● HttpServletRequest request – request object (same as servlet request object) ● HttpServletResponse response – response object (same as servlet respons object) ● HttpSession session – container for session objects
15
Java Beans
16
Java Beans Fundamentals ● a constructor with no arguments ● matching get*, set* public methods
17
Using Beans in a JSP ●
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.