<document>

The JSP actions can be escaped using <\%.

<example> <\% verbatim text %> </example> <results> <% verbatim text %> </results>

JSP whitespace is copied to the output directly, unless escaped.

In Resin 1.2, if you place a backslash immediately after a JSP action and before a line end, Resin will omit the end of line. In the following example, Resin keeps the whitespace after the <%@page ... %> and removes it after after the <%= 2 + 2 %>.

<example> <% @page session="true" %> a <%= 2 + 2 %>\ c </example> <results> a 4c </results>

Sets a JSP directive

Prints the value of expression evaluated the page's language.

The expression action is equivalent to the following:

<def> out.print(expression); </def>

It also has the following XML equivalent

<def> <jsp:expression> expression </jsp:expression> </def>

The following simple example just prints the value of a form variable.

<example> Name: <%= request.getParameter("name") %> </example> <results> Name: George Washington </results>

Executes the statements in scriptlet using the page's language.

The scriptlet is any statement list in the language, e.g. Java. The scriptlet can use any of the implicit variables, such as the request object and the out writer.

Scriptlets have the following XML equivalent

<def> <jsp:scriptlet> scriptlet </jsp:scriptlet> </def> <example> <h1>Form results</h1> <pre> <% Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String key = e.nextElement(); String value = request.getParameter(key); out.println(key + ": " + value); } %> </pre> </example> <results> <h1>Form results</h1> <pre> Name: George Washington Rank: General </pre> </results>

Adds declaration code to the Servlet class

JSP places the declaration code in the servlet class. In contrast, scriptlet and expression code are in a service method. So declarations can declare class variables and methods.

<note>Declarations are primarily useful for Java, but are allowed in JavaScript.</note>

Declarations have the following XML equivalent

<def> <jsp:declaration> declaration </jsp:declaration> </def> <example> <%= foo() %> <%! private int foo() { return 1329; } %> </example>

Includes the contents of the local URL at path during runtime.

jsp:include is a runtime action. It will call the included path just as if path its own HTTP request. The result of that page will be included in the current page.

path is relative to the current page. Its root is the root of the application.

For compile-time includes, use <%@ include file='path'%>

<%= 2 + 2 %> Header <jsp:include page='inc.jsp'/> Footer <results> Header 4 Footer </results>

Forwards the request to another page, i.e. an internal redirect.

If the page has already written some output, jsp:request will clear the output buffer.

path is relative to the current page.

<%= 2 + 2 %> Header <jsp:forward page='inc.jsp'/> Footer <results> 4 </results>

Creates a new bean and variable for the page.

<deftable>
Attribute Value Meaning
id The variable name for the bean
class The bean's Java class
scope
page Only active in the page, stored in pageContext
request Active for the request, stored in request
session Active for the session, stored in session
application Active for the application, stored in application
</deftable>

jsp:useBean enables a popular style JSP page creation where Java Beans calculate the content, and JSP formats the presentation.

jsp:useBean creates an initializes a JSP bean for the page. The scope attribute determines the bean lifetime. For example, a session bean will be created once in a session.

jsp:useBean assigns the bean to the variable name. It will also store the bean in the appropriate scope variable. For example, an application bean "foo" will be stored in the application variable.

jsp:useBean can also initialize beans. When jsp:useBean creates a new bean, it will execute the JSP in the jsp:useBean tag.

Roughly, JSP makes the following translation:

<example> <jsp:useBean id='foo' class='com.caucho.test.TestBean' scope='session'> <% foo.myInitialization("test"); %gt; </jsp:useBean> <def> com.caucho.test.TestBean foo; foo = (com.caucho.test.TestBean) session.getValue("foo"); if (foo == null) { foo = new com.caucho.test.TestBean(); session.value.foo = foo; foo.myInitialization("test"); } </def>

Prints a bean property.

<deftable>
Attribute Meaning
name The variable name for the bean
property The property name to retrieve.
</deftable>

jsp:getProperty converts property names following the bean standards.

Roughly, jsp:getProperty makes the following conversion:

<example> <jsp:getProperty name='foo' property='bar'/> <def> out.print(foo.getBar()); </def>

Sets a bean property to value.

<deftable>
Attribute Meaning
name The variable name for the bean
property The property name to set.
value The value to set.
</deftable>

If value is a runtime attribute, the bean property gets the expression value. If it's a static string, the value is first converted to the argument type and then set.

<example> <jsp:setProperty name='foo' property='count' value='10'/> <results> foo.setCount(10); </results> <example> <jsp:setProperty name='foo' property='string' value='10'/> <results> foo.setString("10"); </results> <example> <jsp:setProperty name='foo' property='count' value='<%= 2 + 2 %>'/> <results> foo.setCount(2 + 2); </results> <example> <jsp:setProperty name='foo' property='count' value='2 + 2'/> <results> error </results> <example> <jsp:setProperty name='foo' property='char' value='10'/> <results> foo.setChar('1'); </results>

Sets a bean property to a parameter value.

<deftable>
Attribute Value Meaning
name The variable name for the bean
property property The property name to set.
*Set all properties
param param The form parameter to use as a value.
empty If missing, use property
</deftable>

The second form of jsp:setProperty lets scripts easily set Bean properties to form values.

</document>