jsp in action
DESCRIPTION
JSP in Action. JSP Standard Actions. JSP Standard Actions f orward , include , useBean , setProperty , getProperty , text , element , and plugin Additional actions p aram , params , attribute , body , and fallback. Actions: forward, include, and param. - PowerPoint PPT PresentationTRANSCRIPT
JSP in Action
JSP Standard Actions
• JSP Standard Actions• forward, include, useBean, setProperty, getProperty, text, element, and
plugin• Additional actions• param, params, attribute, body, and fallback
Actions: forward, include, and param• The forward action lets you about execution of the current page and
transfer the request to another page:
• The include action is similar to forward, the main difference being that it returns control to the including page after the included page has completed execution.
• Note that Tomcat clears the output buffer upon executing the forward action. Therefore, the HTML code generated up to that point by the current page is lost.
• The include action does not clear the output buffer.• The flush attribute (default false) ensures that the HTML generated so
far by the including page is sent to the client before executing the included page.• <jsp:include page=“…”/> is not the same as <%@include file=“...”%>
Action: useBean• jsp:useBean accepts the attributes beanName, class, id, scope, and
type, of which only id is mandatory.• <jspuseBean id=“objName”/>, Tomcat will check whether an object
named objName exists in pageContext.• If you type <jsp:useBean id=“objName” scope=“aScope”/> with
aScope set to one of the words page, request, session, or application, Tomcat will create a variable ojbName of the same type as the object, so that you can access the object in subsequent JSP scripting elements.
• Also jsp:useBean can create new objects. Whether the useBean does it and what type of variable it makes available for JSP scripting depends on the three remaining attributes: class, type, and beanName.• A serialized bean of the xxx.yyyx.Zzz class is expected to be in the
WEB-INF\classes\xxx\yyy\Zzz.ser file.• If you specify type and set it to a fully qualified class name but specifiy
neither class nor beanName, Tomcat won’t instantiate any object and will instead look for it in the given scope.
• The following code instantiates a MyClass object that remains available as long as the session remains valid:
• You’ll be able to access it via a scripting variable name myObj in any page within the same session with the following statement.
• Equivalent to
• And
Actions: setProperty and getProperty• A bean property is nothing else than an attribute of a bean’s class, but
only when you define for that attribute the standard get and put methods. Both get and put must be there. Otherwise, that class attribute is not a bean property.
• Setting values
• Sends the value of the property to the output.
Action: text• You can use the jsp:text action to write template text. Its syntax is
straightforward:
<jsp:text> Template data </jsp:text>
• Its body cannot contain other elements; it can only contain text and EL expressions.
Actions: element, attribute and body• With the actions element, attribute, and body, you can define XML
elements dynamically within a JSP page. • XML generated at request time not at compile time.
Action: plugin, params, and fallback• How to embed an object in a web page.
Comments and Escape Characters• <%-- .. --%> • /* .. */