Docsity

java server, Slides of Advanced Computer Programming

Toggle sidebar
bg1
IT355: Internet Technologies & Programming
Java Server Pages (JSP)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34

Partial preview of the text

Download java server and more Slides Advanced Computer Programming in PDF only on Docsity!

IT355: Internet Technologies & Programming

Java Server Pages (JSP)

Introduction

  • (^) Java Server Pages (JSPs or JSP Pages) technology is introduced in late 1999 as a new Java API and an extension of servlet.
  • (^) JSPs generate HTML pages with dynamic content.
  • (^) Unlike servlets, JSPs are not Java programs, but HTML documents with embedded Java code supplied via HTML- style tags.
  • (^) A JSP file must have the suffix .jsp to be recognized by a JSP-aware Web server.
  • (^) We can use Tomcat or GlassFish to test JSPs.

Why Use JSP?

  • (^) Servlets can be used to generate dynamic Web content.
  • (^) One drawback, however, is that you have to embed HTML tags and text inside the Java source code.
  • (^) Using servlets, you have to modify the Java source code and recompile it if changes are made to the HTML text.
  • (^) Java Server Pages (JSP) technology was introduced to remedy this drawback.
  • (^) JSP enables you to write regular HTML script in the normal way and embed Java code to produce dynamic content.

Example: ShowIP

IPServlet.java

Result.jsp

How is a JSP Page Processed?

JSPs and Servlets

  • (^) JSPs don’t make servlets redundant.
  • (^) Servlets provide overall control a to all/part of Web site.
  • (^) A servlet can receive HTTP requests, determine what to do, carryout background processing and pass control to a JSP or ordinary HTML page (possibly selected from a number of candidates).
  • (^) They are complementary technologies.

Compilation and Execution

  • (^) JSPs are placed in the same folder as HTML pages (for Tomcat server).
  • (^) When a JSP is first referenced by a server, it is converted into a servlet which is then compiled and stored on the server.
  • (^) Because of the conversion-compilation- execution process, there is a noticeable delay for the first access.
  • (^) To avoid this, pre-compiled JSPs may be used.
  • (^) Provide jsp_precompile just like any other request parameter. For example, MyPage.jsp?jsp_precompile will trigger the precompilation of MyPage.jsp

JSP Tags

  • (^) Categories of JSP-specific tags used on a Java Server Page: 1. Directives 2. Declarations 3. Expressions 4. Scriptlets 5. Comments 6. Actions
  • (^) We will discuss them separately.
  • (^) Note that all of the keywords must be in lower case.

Three JSP Directives

page

include tablib Three possible directives are the following: page, include, and tablib.

page lets you provide information for the

page, such as importing classes and setting

up content type. The page directive can

appear anywhere in the JSP file.

Three JSP Directives page

include

tablib Three possible directives are the following: page, include, and tablib.

include lets you insert a file to the servlet

when the page is translated to a servlet. The

include directive must be placed where you

want the file to be inserted.

Attributes for page Directives import contentType session buffer autoFlush isThreadSafe errorPage isErrorPage

Specifies one or more packages to be

imported for this page. For example, the

directive <%@ page import="java.util.*,

java.text." %> imports java.util. and

java.text.*.

Attributes for page Directives import contentType session buffer autoFlush isThreadSafe errorPage isErrorPage

Specifies the type for the resultant JSP

page. By default, the content type is

text/html for JSP. The default content type

for servlets is text/plain.