1 / 22

JSP in Action

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.

lupita
Download Presentation

JSP in Action

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSP in Action

  2. JSP Standard Actions

  3. JSP Standard Actions • forward, include, useBean, setProperty, getProperty, text, element, and plugin • Additional actions • param, params, attribute, body, and fallback

  4. Actions: forward, include, and param • The forward action lets you about execution of the current page and transfer the request to another page:

  5. 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.

  6. 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.

  7. 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=“...”%>

  8. 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 objNameexists in pageContext. • If you type <jsp:useBean id=“objName” scope=“aScope”/> with aScopeset to one of the words page, request, session, or application, Tomcat will create a variable ojbNameof the same type as the object, so that you can access the object in subsequent JSP scripting elements.

  9. Also jsp:useBeancan create new objects. Whether the useBeandoes 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.

  10. 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 myObjin any page within the same session with the following statement.

  11. Equivalent to • And

  12. 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.

  13. Setting values

  14. Sends the value of the property to the output.

  15. 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.

  16. 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.

  17. Action: plugin, params, and fallback • How to embed an object in a web page.

  18. Comments and Escape Characters • <%-- .. --%> • /* .. */

More Related