Java Intermediate -JSP nine built-in objects and actions

First, the built-in objects

  In JSP, also known as built-in objects hidden object refers to a number of member variables without declaration and created can be used. JSP provides a total of nine built-in objects, which are request (in response to the object), the pageContext (page context object), the session (session object), file application (application object), OUT (output target), config (configuration object), page (page object) with the exception (the exception object). A detailed description thereof as follows:

 

  Depending on their function, nine or more built-in objects can be divided into four types: the first type, page, and related config and Servlet; second, and Input / Output related out, request and Response; third category, Context associated with the application, session, and the pageContext; fourth category, associated with the Error exception.

Second, the built-in motion

  JSP uses dynamic motion to insert documents, references, and redirection function of JavaBean. It is a total of six basic actions: jsp: include, jsp: useBean, jsp: setProperty, jsp: getProperty, jsp: forward and jsp: plugin.

  jsp: include: to introduce a document when the page is requested. include directive was introduced in the JSP file is converted to a file when the Servlet, and jsp: include the time when the document is inserted in the requested page, and the referenced file can not contain certain JSP code (e.g., HTTP headers can not be set). Use example:

<jsp:include page="test.jsp" flush="true">
<jsp:param name="name" value="value"/>
</jsp:include>

  Above may be introduced test.jsp code represents a file in the current file.

  jsp: useBean: used to search or instantiate a JavaBean. It enables developers to reuse Java components can either play advantage, but also to avoid the loss of convenience JSP Servlet different from the. Use example:

<jsp:useBean id="car" scope="session" class="com.Car">

  The above code shows an example of an instance of a class com.Car.

  jsp: setProperty: to set the properties of instantiated objects Bean. Example follows:

<jsp:setProperty name="car" property="colour" value="red" />

  The above code is used to set the name of the instance attribute colour car is red.

   jsp: getProperty: used to obtain a JavaBean property. Use example:

colour=<jsp:getProperty name="car" property="colour"></jsp:getProperty>

  This code is used to get the name of the car colour instance attributes.  

  jsp: forward: to the request to a new page. Use example:

<jsp:forward page="/Servlet/login" />

  The above code page is redirected to the current / Servlet / login treated.

  jsp: plugin: for play or display an object in the browser. This action can insert the required use of browser-specific OBJECT or EMBED element needed to specify the browser to run a JAVA Applet plug-ins. Use example:

<jsp:plugin type="applet" codebase="/ch5" code="Hello.class" height="40" width="320">

  This code is used to run an applet plugin in the browser.

Guess you like

Origin www.cnblogs.com/myl0205/p/11406204.html