Java - JSP / nine built-in objects / four domain objects

A, the JSP : ( Java-Service Pages ) : is the dynamic resource JavaWeb server;

  // it effect the same html page, data acquisition and data display;

Two, the JSP code is composed of: HTML + the Java script (code segments) + JSP dynamic label;

 

Three, the JSP three instructions : <% @  directive attribute name = "value" %>

  1.page<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

    (. 1 ) Language = "Java": Java language;

    (2 ) contentType = "text / HTML; charset = UTF-. 8": page content and code;

    (. 3 ) the pageEncoding = "UTF-. 8": encoding format;

    (4) import = "java.lang *.": The leader packet;

    (5 ) session = "to true": whether to open session function;

    (6 ) isELIgnored = "false": whether to ignore EL expressions; // isELIgnored = 'true' to disable EL, isELIgnored = 'false' representation can use EL, the default is false

  2.taglib tag library is introduced: <% @ taglib  URI = "" prefix = "" %>

    // JSTL tag library is introduced: <% @ taglib URI = "http://java.sun.com/jsp/jstl/core" prefix = "C"%>

  3.includ static introduced: <% @ includ- File = "" %>

     Value // file must be a relative path; if at the beginning of "/" indicates the root directory of the web application (not the site);

    // Example: in the same directory: "style.css";    

    The lower directory:

    1“/css/style.css"

    2“css/style.css"

Fourth, Tags:

( 1 ) a script tag: <%>

( 2 ) declare tags: <% !     %>  

  // global variables: <!% Int i = 0;%> Multiple calls superimposed;

  // local variables: <int I = 0%;%> not overlap;

( 3 ) expression tag: <% =     %>

(4 ) comment tags: <% - -%>

(5 ) Label directive: <% @%>

( 6 ) Action Tags: <JSP: the Name Action />

label

effect

use

jsp:include

The introduction of a file when the page is requested.

 

jsp:forward

The request to a new page.

 

jsp:useBean

Or looking for instantiating a JavaBean.

<Jsp: useBean id = "new object named" class = "fully qualified name" scope = "page"> </ jsp: useBean>

jsp:setProperty

Set JavaBean properties.

<Jsp: setProperty name = "id" property = "attribute name" value = "attribute value" />

jsp:getProperty

The output of a JavaBean properties.

<jsp:getProperty name="id" property="属性名" />

Five, JSP built-in objects and Servlet correspondence between:

Implicit object ( the JSP )

Description ( Servlet )

out

Corresponding to the post-translational JspWriter object inside the object associated with a PringWriter; //response.getWriter ();

 request

Corresponding to the post-translational the HttpServletRequest / the ServletRequest objects;

response

Corresponding to the post-translational HttpServletRespons / ServletResponse objects;

config

Corresponding to the post-translational ServletConfig object;

 application

Corresponding to the post-translational ServletContext objects;

 session

Corresponding to the post-translational HttpSession objects; // <%% @ page session = "false"> set invalid session;

 pageContext

Corresponding to the post-translational PageContext object that provides a packaging JSP page resources, and set page range properties;

exception

After the translation corresponds Throwable object that represents the exception object thrown by other JSP pages,

It will only appear in the JSP error page (isErrorPage set to true the JSP page);

page

Corresponding to the post-translational this;

Two, JSP built-in objects Description:

  1. OUT output object: is an output stream; means for outputting various data to the client; 

  2.request request object: encapsulating information request submitted by the client, the information may be obtained by encapsulating the appropriate object method call;

  3. Response in response to: the client's dynamic response to a request made, sending the data to the client;   4.config configuration objects: Examples of javax.servlet ServletConfig; generally often used in a Servlet;. 

  5.application application object: the server started to generate a target application, all clients share a single object;

  6.session session object: client generates a session object after the end open the browser to connect the server until the browser is closed this object was destroyed;

  7.pageContext page context object: Examples of javax.servlet.jsp.PageContext; by this object can get other 8 large built-in objects;

  8.exception targeted for exception: Exception / error;

  9.page page object: java.lang.Object; this corresponds to the keyword; jsp page itself; page = this;

Three, four domain objects:

  1.pageContext: current page; // minimum range;

  2.requset: the current request; // request forwarding can be accessed across multiple pages, refresh the destruction;

  3.session: current session;

  4.application: current service;

  // nine built-in object scope: In addition to Request , the session , the Application other objects are all scopes Page ;

Fourth, use:

(. 1 ) the Servlet can be used in request, session, application objects three domains;

(2 ) the JSP may be used pageContext, request, session, application domain objects four;

 

 

Guess you like

Origin www.cnblogs.com/Tractors/p/11263349.html