meljun cortes developing jsp
TRANSCRIPT
-
8/11/2019 MELJUN CORTES Developing JSP
1/18
JSP TechnologyJavaServer Pages (JSP) enable youto write standard HTML pagescontaining tags that run powerfulprograms based on the Javaprogramming language.
JSP is capable of returning staticand dynamic content.
It allows separation of presentationand business logic.
MELJUN ORTES
-
8/11/2019 MELJUN CORTES Developing JSP
2/18
Hello Servlet Code
public void generateResponse(HttpServletRequestrequest,HttpServletResponse response) throwsIOException {
// Determine the specified name (or usedefault) String name =request.getParameter("name"); if ( (name == null) || (name.length() ==0)) { name = DEFAULTJSTAME;
// Specify the content type is HTMLresponse.setContentType("text/html");PrintWriter out = response.getWriter();
// Generate the HTML responseout.printIn("");out.println("");out.println("Hello Servlet");out.println("");out.println("");out.printIn("Hello, " + name + "");out.printIn("");out.println("");out.close();
-
8/11/2019 MELJUN CORTES Developing JSP
3/18
-
8/11/2019 MELJUN CORTES Developing JSP
4/18
-
8/11/2019 MELJUN CORTES Developing JSP
5/18
JSP Lifecycle Phases
Translation phase
Compile phase
Execution phase
-
8/11/2019 MELJUN CORTES Developing JSP
6/18
JSP Scripting ElementsJSP scripting elements areembedded with the tags andare processed by the JSP engineduring translation of the JSP page.
-
8/11/2019 MELJUN CORTES Developing JSP
7/18
JSP Scripting ElementsThere are five types of scriptingelements:
1. Comments 2. Directive tag 3. Declaration tag 4. Scriptlet tag 5. Expression tag
-
8/11/2019 MELJUN CORTES Developing JSP
8/18
CommentsDocumentation is important to anyapplication. There are two types ofcomments permitted in a JSP page:
HTML comments
JSP page comments
-
8/11/2019 MELJUN CORTES Developing JSP
9/18
CommentsJava comments can be embeddedwith scriptlet and declaration tags.
/* This is a Java comment. It willshow up in the servlet code. It willnot show up in the response. */
-
8/11/2019 MELJUN CORTES Developing JSP
10/18
Directive TagA directive tag provides informationthat will affect the overalltranslation of the JSP page.
The syntax for a directive tag is:
Example:
-
8/11/2019 MELJUN CORTES Developing JSP
11/18
The page DirectiveThe page directive is used tomodify the overall translation ofthe JSP page.
Page dependent properties of thepage directive:
language attributeextends attributeimport attribute
session attributebuffer attributeautoFlush attributeisThreadSafe attribute
info attributeerrorPage attributeisErrorPage attributecontent T e attribute
-
8/11/2019 MELJUN CORTES Developing JSP
12/18
Declaration TagA declaration tag allows you toinclude members in the JSP servletclass, either attributes or methods.
The syntax for a declaration tag is:
Example:
-
8/11/2019 MELJUN CORTES Developing JSP
13/18
Declaration TagYou can use a declaration tag tooverride the jsplnit() andjspDestroy() life cycle methods.
The signature of these methods hasno arguments and returns void .
Example:
-
8/11/2019 MELJUN CORTES Developing JSP
14/18
Scriplet TagA scriptlet tag allows the JSP pagedeveloper to include arbitrary Javatechnology code in the
_jspService() method.
The syntax for a scriplet tag is:
Example:
10 ) { %>
I is a big number.
I is a small number
-
8/11/2019 MELJUN CORTES Developing JSP
15/18
Scriptlet with Loop
...
-
8/11/2019 MELJUN CORTES Developing JSP
16/18
Expression TagAn expression tag holds a Javalanguage expression that isevaluated during an HTTP request.The result of the expression isincluded in the HTTP responsestream.
The syntax for a expression tag is:
Example:
Ten is
Thank you, ,for registering for thesoccer league.
The current day and time is:
-
8/11/2019 MELJUN CORTES Developing JSP
17/18
-
8/11/2019 MELJUN CORTES Developing JSP
18/18
Implicit Variables
Variablename
Description
application The ServletContext object for theWeb application.
config The ServletConfig object associated
with the servlet for the JSP page.pageContext This object encapsulates the
environment of a single request forthis JSP page.
page This variable is equivalent to the thisvariable in the Java programminglanguage.
exception The Throwable object that wasthrown by some other JSP page. Thisvariable is only available in a "JSPerror page."