JSP's thirty-six thousand nine hundred forty-seven (three instructions, six labels, nine built-in objects, the four scopes, seven operation command)

Basic structure of the JSP: HTML File + Java + JSP tag snippet

Three instructions : page directive, include directive, taglib directive.

page directive:

1.language property: Set JSP scripting language used to write the current page, the default is java.

                                        <%@page language="java"%>

2.contentType properties: set page response MIME type, is generally set to text / html.

                                        <%@page contentType="text/html"%>

                                   You can also set the character encoding JSP:

                                       <%@page contentType="text/html;charset=gb2312"%>

3.import property: similar import statement in Java, will need to import the package to the JSP file.

                          This property can be used repeatedly in the page directive to import more packages. E.g:

                          <%@page import="java.util.*" %>

                          <%@page import="java.text.*"%>

                         Or by commas to separate, to import more packages.

                         <%@page import="java.util.*,java.text.*"%>

JSP has been imported by default in the following pack.

  • java.lang. *
  • java.servlet.*
  • java.servlet.jsp.*
  • java.servlet.http.*

4.extends property:

5.session property: This property defaults ture, the current page support session.

6.buffer property :( buffer)

7.autoFlush property:

8.isThreadSafe property:

9.info property: This property can be set to any string, such as the author of the current page or other relevant page information. By strings may be Servlet.getServletInfo () method to set. E.g:

<%@page info="This is index.jsp!"%>

<%=this.getServletInfo()%>

After visiting the page, show the following results: This is index.jsp!

10.errorPage isErrorPage properties and attributes:

For example: if the current application contains at index.jsp and error.jsp file.

Data type conversion operation index.jsp page, the code is as follows.

<%@page contentType="text/html;charset=utf-8" errorPage="error.jsp"%>
<%
String name="YXQ";
Integer.parseInt(name); //将字符串转化为int型
%>

The code string of a non-digital format into int type, the exception occurs, eventually enter errorPage attribute specifies error.jsp page displays an error message.

You need to isErrorPage property to true in error.jsp page, before you can call the exception object output an error message.

error.jsp page code is as follows.

<%page contentType="text/html;charset=gb2312" isErrorPage="true"%>
出现错误!错误如下:<br>
<%=exception.getMessage()%>

include instruction:

<% @ Include file = "absolute or relative path to the file path"%>

Referenced using an external file include directive, the redundant code can be reduced. (Eg: page Public)

<%@page contentType="text/html;charset=utf-8"%>
<table>
<tr><td colspan="2"><%include file="top.jsp"%></td></tr>
<tr>
<td><%@include file="side.jsp"%></td>
<td>内容显示</td>
</tr>
<tr><td colspan="2"><%@include file="top.jsp"%></tr>
</table>

taglib directive:

Six Tags: pseudo-instruction tag: <% @%>

                    Comment tags: <% - -%>

                    Disclaimer tags: <!%%>

                   Action Tags: <jsp: action Name />

                    Script tags: <%%>

                   Tags expression: <% =%>

Nine built-in objects:  Request, the Response, the session, applicatin config, Exception OUT, Page, pageContext,

Four scopes:

JSP scopes

JSP page objects, including built-in objects and JSP has a range of user-created property.

Application-- objects with application scope, survival during the application are available.

Session-- objects with a session scope, available during the session alive.

Request-- objects with request scope, can be accessed within the inside pages of all working on the same request.

Page-- objects with page scope, can be used in the current page

方法:setAttribute(String name,Object  attribute)

           getAttribute(String  name)

Scope range from big to small:

Allication Scope: maximum range

                               Can be shared by different pages, different users

                                By Allication built-in objects or ServletContext

                              Access Allication scope object

Session scope: Scope range after Allication

                             It may be the end of the same customer access request

                             Session scope objects can be accessed through the built-in objects Session

Request Scope: Session scope range of less than

                            May be turning a page or include forward () method () contains page views

                           Request scope object can be accessed through the built-in objects request

page scope: the minimum range

                      You can only object to be created Page Views

                       Page can be accessed only by the scope of the object pageContext built-in objects

 

JSP seven action directives:

jsp: forward: page jump, in fact, request.getRequestDispatcher ( "index.jsp") forward (request, response) evolved.

jsp: param: used to pass parameters, the prerequisite is to be used in conjunction with other support its label

jsp: include: for dynamically embedded in another page in the current JSP the JSP (JSP page contained is achieved by a process comprising dynamically, and only the content contained <body>, is relatively static comprising no duplication of statement)

jsp: plugin: Applet or JavaBean for download to the client execution

jsp: userBean: Create a JavaBean instance, in fact, create a similar object instance <%> java code block

jsp: setProperty: set the attribute value instances JavaBean

jsp: getProperty: getting a property value JavaBean instance

Guess you like

Origin blog.csdn.net/sinolover/article/details/95178176