CS6320:  SW Engineering of Web Based Systems

 

JSP Scripting Elements

The Idea:

Specifies code that will become part of Servlet produced from server traslation of .jsp file.

Kinds of Scripting Elements:

 

Expressions

 <%= expression %>

expression is evaluated and inserted into Servlet’s output.

Scriplets

<% code %>

This code is directly inserted into the produced Servlet’s _jspService() method.

This method is automatically called by the Servlet’s service() method.

Declarations

<%!  code  %>

The code is inserted into the body of the produced Servlet, outside of any existing method (like _jspService())

 

Comments

  <%--  comment  --%>

Difference between this an HTML comment is this is inserted into the Servlet being produced by evaluating the .jsp file.

 

 

 

Expressions

The expression is evaluated, and then converted to a string and inserted into the page resulting from output of produced Servlet

Unlike scriplets, meant for simple kinds of commands.

Often will reference one of a number of predefined variables.

<%= your_expression %>

 

<jsp:expression>

your_expression

</jsp:expression>

Example from Book

EXERCISE

Scriplets

This code is directly inserted into the produced Servlet's _jspService() method.

Used for more complicated pieces of code. Like DB access, File I/O, computations, invokation of other classes, servlets, etc.

EXERCISE

EXERCISE2 (must turn in)

Declarations

EXERCISE (must turn in)

 

© Lynne Grewe