JavaWeb-JSP entry

What is JSP

JSP full name of the Java Server Pages, Chinese named java server pages, which is a traditional Web page HTML files ( .htm, insert the Java and JSP tag block .html), the suffix (* .jsp), its fundamental Servlet is a simplified design.

Why should there be JSP

Html files directly is no way to output information among Java, a web page using a servlet output to come and go very trouble, so it was a jsp, but also write html, but also to write Java code.

Part of the JSP

  1. Static data, such as HTML
  2. JSP scripting elements and variables
  3. JSP instructions, such instructions include
  4. JSP tag action
  5. User-defined labels

JSP scripting elements and variables

  • Write Java code in JSP them
  1. <% Java code%> for output.
  2. <%! Java code%> member variables used to define properties and methods.
  3. <% = Java variables or expressions%> service method will be translated into an internal Out.print ()
  • JSP comments
    HTML comments: visible range jsp source code, servlet translated page
    Java annotations
    Jsp comment <% - Comment content -%>

JSP directives

  • What is the command
    JSP instructions for setting information related to the entire JSP page, and for communication between the JSP pages and other containers.
  • page instructions: to set the properties and functions of the entire relevant JSP page, separated by spaces between a plurality of attributes.
instruction Features
contentType contentType attribute specifies the MIME encoding format and JSP pages
pageEncoding pageEncoding property is used to specify the encoding format JSP file
import Introduced in JSP Java package and class, among a plurality of packets with commas
session Specify whether the current page to get the current user session object default is true, if you specify false, the session can not be used in this page, you will be prompted to use the words of 500 error
errorPage Exception occurs if the current page, the page will be redirected to the page specified errorPage processing
language property Specifies the scripting language used in the page, currently only supports java
extends Is used to specify the JSP servlet which generates inherited from the parent class, you must specify the package name plus the class name
buffer To set the output stream buffer, the buffer zone is to improve IO performance, i.e. to reduce the number of write
autoflush When used to specify the output stream buffer is full time, whether or not auto-refresh buffer
isThreadSafe The default value is true, specify whether the JSP file support multithreaded access
info Provides information used to set the jsp file
isELIgnored EL expression used to indicate whether to support
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
  • include directive
    indicates when compiled JSP file or insert contains a code, include the file name contained in the instruction is not a variable url, only the file name is static. The two together then jsp page, and then translated into a servlet. settings file attribute must use a relative path.
<%@ include file="被包含的的文件的地址"%>
  • taglib directive
    role: Declare JSP file using the tag library
    which tag libraries:
  1. JSP Standard Tag Library
  2. Third-party tag library
  3. Custom tag library

jsp action elements

Page contains: <jsp: include page = "included in the page"> </ jsp: include>
Dynamic comprising respective own page translation, and then reintroduced.
Forwards the request: <jsp: forward page = "resources to be forwarded"> </ jsp: forward>

Implicit Objects

After being translated into jsp servlet, service process and object definitions nine initialized.

out Type out of: JspWriter, out the role of a client just wanted to output content out.write (), out buffer default 8kb, it can be set to 0 for close out the buffer contents written directly respons buffer, out to write the content is written out among the buffer, and finally the buffer contents out among them incorporated into the response buffer.
request Obtain user requests information object
config Server configuration, you can get initialization parameters
session Used to store user session information
application Sharing of information for all users, it is servletContext
page It refers to an instance of the current page after conversion Servlet class
pageContext Jsp page context object, is a domain object.
exception JSP pages represent an exception occurred, only play a role in the error page, only it's time error pages, will have the object.

pageContext:
access to the specified data to another domain , can be obtained other eight major implicit object .

setAttribute(“name”,"lk",PageContext.REQUEST_SCOPE);
getAttribute("lk",PageContext.REQUEST_SCOPE)/*自动到所有的域当中找数据
从小到大的范围搜索数据
依次从pageContext域,request域,session域,application域中获取属性
在某个域中获取后将不在向后寻找
*/
findAttribute(String name)
pageContext.getRequest();
pageContext.getSession();
Published 25 original articles · won praise 0 · Views 275

Guess you like

Origin blog.csdn.net/qq_42219004/article/details/105327715