Вы находитесь на странице: 1из 18

JAVA SERVER PAGES

VAMSOFT TECHNOLOGY & CONSULTANCY PVT LTD

JSP (Java Server Pages)


User request

Web server/servlet engine Check to see if the file has changed since last compiled

Jsp handler servlet

Jsp source code

Existing servlet

File changed? yes Create source file

No,execute existing servlet

Compile to a servlet
Trendsetters for the future

Execute new servlet


2

IMPLICIT OBJECTS IN JSP


request - Encapsulates the client request. Usually a sub class of HttpServletRequest response - Encapsulates the servers response. Usually a sub class of HttpServletResponse session - Object of HttpSession. The session object associated with every client. Used to store client data.

Trendsetters for the future

IMPLICIT OBJECTS IN JSP


out - object representing the output stream. exception - uncaught subclass of Throwable that is passed to the error page URL. config - object representing the ServletConfig. application - Object of ServletContext. Used to store global info. To be shared by all the clients.

Trendsetters for the future

COMPONENTS OF A JSP PAGE


SCRIPLETS - <% %> - Any block of java code that will be ultimately placed inside the service() method of the generated servlet EXPRESSIONS - <%= %> - formats the expression as a string for inclusion in the output.
Trendsetters for the future 5

COMPONENTS OF A JSP PAGE


DECLARATIVES - <%! %> - these are for page-wide variable and method declarations. DIRECTIVES - <%@ %> - A statement that gives the JSP engine global information about the page that follows. Ex: import,bugger,error handler etc.
Trendsetters for the future 6

DIRECTIVES
Directives are elements that provide global information, about an entire JSP page. Three types of directives Page Directive Include Directive Taglib Directive

Trendsetters for the future

ATTRIBUTES OF A PAGE DIRECTIVE


<%@ directive attribute=value %> ATTRIBUTE language=scripting import=import list DEFINITION This attribute tells the server what language is used to compile the server. This attribute specifies the list of packages available to this jsp. The packages are seperated by commas. Specifies that the jsp engine can service more than one thread is set to true.
Trendsetters for the future

isThreadSafe=boolean

ATTRIBUTES OF A PAGE DIRECTIVE


ATTRIBUTE errorPage=filename isErrorPage=boolean DEFINITION Refers to the file name which will handle the exceptions. This attribute states whether or not a jsp page is an error page. Default is false.

Trendsetters for the future

ATTRIBUTES OF A INCLUDE DIRECTIVE


The include directive is used to insert text and code at jsp translation time. <%@ include file=file name%> Example: <%@ include file= abc.html%>

Trendsetters for the future

10

ACTION TAGS
Actions are used for encapsulating common tasks. Especially used to create objects of java beans. <jsp:include> <jsp:forward> Includes static and dynamic page. Dispatches the current page to another resource (html, servlet, jsp). Used to pass values using a name and value pair.
Trendsetters for the future 11

<jsp:param>

ACTION TAGS
<jsp:useBean> <jsp:setProperty> <jsp:getProperty> Associates an instance of a Bean. Sets the Value for the Bean Property Retrives the Value from the Bean Property
Trendsetters for the future 12

<jsp:include> Action

<jsp:include page= filename />

Trendsetters for the future

13

<jsp:forward> Action
<jsp:forward page= filename /> <jsp:forward page= filename > <jsp:param name=variable name value = variable value/ > </jsp:forward>

Trendsetters for the future

14

ATTRIBUTES OF <jsp:useBean> ACTION


ATTRIBUTE id scope class DEFINITION This attribute gives the identity of the instance. This attribute represents the life of the object. refers to the class name of the bean.

Trendsetters for the future

15

ATTRIBUTES OF <jsp:setProperty> ACTION


ATTRIBUTE name DEFINITION This attribute refers to the name of the bean instance (same as id) Name of the bean property to which a value is set. The value that is set to the referred bean property.
Trendsetters for the future 16

property value

ATTRIBUTES OF <jsp:getProperty> ACTION


ATTRIBUTE name property DEFINITION This attribute refers to the name of the bean instance (same as id) Name of the bean property from which the value is retrieved.

Trendsetters for the future

17

JSP ERRORS
Two types of errors Translational errors : - occurs during the initial request. - Handled by jsp engine. Request time errors : - occurs during subsequent requests.

Trendsetters for the future

18

Вам также может понравиться