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,
Published byModified over 5 years ago
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:
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
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
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
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
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
E.g. <% String userName=null; userName=request.getParameter(“userName”); %>
Expression Expression is evaluated and placed in output E.g. Puts the value of title into the output
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.
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.