Java Server Pages - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Java Server Pages

Description:

Java Server Pages Russell Beale What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user, with small ... – PowerPoint PPT presentation

Number of Views:131
Avg rating:3.0/5.0
Slides: 14
Provided by: Peter1554
Category:
Tags: java | pages | server | servlet

less

Transcript and Presenter's Notes

Title: Java Server Pages


1
Java Server Pages
  • Russell Beale

2
What are Java Server Pages?
  • Separates content from presentation
  • Good to use when lots of HTML to be presented to
    user, with small amounts of processing
  • Uses java
  • But is a bit like asp, php, perl etc.
  • Page compiled to a servlet when first executed

3
Uses
  • Often jsp pages used to present the information
    to the user
  • Developers code the servlets, called from the jsp
    page
  • Designers code the HTML to pull all these
    different components together

4
JSP pages
  • Text file containing HTML (or XML) along with JSP
    elements, which are shorthand for java code
  • The JSP parts provide the dynamic content
  • In tags
  • lt gt
  • Give file a .jsp extension, (typically) put it
    wherever you would a web page

5
JSP page constructs
  • HTML
  • Most of the page - known as template text
  • Scripting elements
  • Specify Java code that becomes part of the
    servlet
  • Directives
  • Control overall structure of servlet
  • Actions
  • Specify existing components that should be used

6
Scripting elements
  • lt
  • java code
  • gt
  • Any amount of java code
  • Variables available
  • request (subclass of HttpServletRequest)
  • response (subclass of HttpServletResponse)
  • session
  • out
  • Known as scriplets as well

7
E.g.
  • lt
  • String userNamenull
  • userNamerequest.getParameter(userName)
  • gt

8
Expression
  • lt expression gt
  • Expression is evaluated and placed in output
  • E.g.
  • lt request.getParameter(title) gt
  • Puts the value of title into the output

9
Directives
  • affects the overall structure of the servlet
    class
  • lt_at_ directive attribute"value" gt
  • two main types of directive
  • page, which lets you do things like import
    classes, customize the servlet superclass, etc.
  • include, which lets you insert a file into the
    servlet class at the time the JSP file is
    translated into a servlet.

10
Declaration
  • lets you define methods or fields that get
    inserted into the main body of the servlet class
    (outside of the service method processing the
    request).
  • lt! Java Code gt
  • declarations do not generate any output -
    normally used in conjunction with JSP expressions
    or scriptlets.

11
Actions
  • Control behaviour of servlet engine

12
Bigger e.g.
  • See index

13
Summary
  • JSP good for
  • Quick and dirty dynamic pages
  • Pages with lots of html and less code
  • Separation of presentation from content
  • JSP pages are converted into servlets for you
Write a Comment
User Comments (0)
About PowerShow.com