Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— Presentation transcript:

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 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 <% java code %> 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. <% String userName=null; userName=request.getParameter(“userName”); %>

8 Expression Expression is evaluated and placed in output E.g. Puts the value of title into the output

9 Directives affects the overall structure of the servlet class 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). 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


Download ppt "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,"

Similar presentations


Ads by Google