JSP implicit objects & directive elements Lec - 35
JSP Journey directive elements ………………………. scripting elements JSP comments………………………………. declarations ………………………………… expressions …………………………..…….. scriptlets……………………………….......... action elements special JSP tags ………………………….…. implicit objects
Implicit Objects
Implicit Objects Objects that can be used in scriplets & expressions without defining them before. request response out Session application config pageContext exception page
Implicit Objects cont. request: javax.servlet.HttpServletRequest request object that is the reason for the servlet to run response: javax.servlet.HttpServletResponse Response for the request out: javax.servlet.jsp.JspWriter Output stream writer
Example of Implicit Objects web.jsp If page = = web index.jsp controller .jsp If page = = java java.jsp
Use of implicit objects Example Code Use of implicit objects
JSP Journey directive elements ………………………. scripting elements JSP comments………………………………. declarations ………………………………… expressions …………………………..…….. scriptlets……………………………….......... action elements special JSP tags ………………………….…. implicit objects
JSP Directives
JSP Directives Used to convey special processing information about the page to JSP container Enable programmer to: Specify page settings Include content from other resources Specify custom-tag libraries
JSP Directives cont. Format JSP directives <%@ directive {attribute=“val”}* %> JSP directives page: <%@ page {attribute=“val”}* %> include: <%@ include {attribute=“val”}* %> taglib: <%@ taglib {attribute=“val”}* %>
JSP page Directive
JSP page Directive Give high level information about servlet that will result from JSP page Can be used anywhere in the document Can control Which classes are imported What class the servlet extends What MIME type is generated How multithreading is handled If the servlet participates in session Which page handles unexpected errors
JSP page Directive cont. Defines attributes of the page <%@ page {attribute=“val”}* %> Some Attributes language = “java” extends = “package.class” import = “package.*,package.class,…” session = “true | false” Info = “text” contentType = “mimeType” isThreadSafe = “true | false” errorPage = “relativeURL” isErrorPage = “true | false” Language specifies what language Directives provide global information that is conceptually valid independent of any specific request received by the JSP page. Compile time information.
JSP page Directive cont. Some example uses are: To import the package like java.util <%@ page import = “java.util.*” info = “using util package” %> To declare this page as an error page <%@ page isErrorPage = “true” %> To generate the excel spread sheet <%@ page contentType = “application/vnd.ms-excel” %> Language specifies what language Directives provide global information that is conceptually valid independent of any specific request received by the JSP page. Compile time information.
JSP include Directive
JSP include Directive Lets you include (reuse) navigation bars, tables and other elements in JSP page You can include files at Translation Time (by using include directives) Request Time (by using Action elements)
Including Pages at Translation Time using include directive Format <%@include file=“relativeURL”%> Purpose To include a file in JSP document at the time document is translated into a servlet. May contain JSP code that affect the main page such as response header settings etc.
use of include directive Example Code use of include directive
Generate Excel Spread-sheets by setting content type Modify Last Example to Generate Excel Spread-sheets by setting content type
XML Syntax for Directives <jsp:directive.directiveType attribute=“value” /> For example, the XML equivalent of <%@ page import = “java.util.*” %> Is <jsp:directive.page import=“java.util.*” />
JSP Journey directive elements ………………………. scripting elements JSP comments………………………………. declarations ………………………………… expressions …………………………..…….. scriptlets……………………………….......... action elements special JSP tags ………………………….…. implicit objects
JSP Life Cycle Methods
JSP Life Cycle Methods jspInit() _jspService() jspDestroy() Request Response _jspService() jspDestroy()