jsp in action. jsp standard actions forward, include, usebean, setproperty, getproperty, text,...

22
JSP in Action

Upload: ezra-francis

Post on 19-Jan-2018

223 views

Category:

Documents


0 download

DESCRIPTION

forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params, attribute, body, and fallback

TRANSCRIPT

Page 1: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

JSP in Action

Page 2: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

JSP Standard Actions

Page 3: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

• JSP Standard Actions• forward, include, useBean, setProperty, getProperty, text, element, and

plugin• Additional actions• param, params, attribute, body, and fallback

Page 4: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

Actions: forward, include, and param• The forward action lets you about execution of the current page and

transfer the request to another page:

Page 5: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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

Page 6: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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

Page 7: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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

Page 8: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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.

Page 9: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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

Page 10: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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

Page 11: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

• Equivalent to

• And

Page 12: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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.

Page 13: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Page 14: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

• Setting values

Page 15: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

• Sends the value of the property to the output.

Page 16: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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.

Page 17: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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.

Page 18: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Page 19: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Page 20: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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

Page 21: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Page 22: JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,

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