JSP (Java server Page)

Source: Internet
Author: User

The constituent elements of JSP;
1, instruction
Page directive
<%@ page ..........%>
Language---Current page language: Java
Import---The class library introduced by the current page, which is not introduced by default
ContentType---text/html; charset= ' character set '
Iso-8859-1 is the default value of the character set, and the plain English character set
Iserrorpage---Define whether the current page is an Error alert page
ErrorPage---Defines the page to jump when the current page is faulted
Include directives
TAGLIB directive
2, expression
<%= Variable name%>
3, Script
<% Code Content%>
4, statement
<%! Code Declaration%>
5, Notes
Visible <!---->
Invisible <%----%>
Comments used in the script
/**/, //

JSP nine large built-in objects:
Built-in objects/scopes (the life cycle of each scope is different):
1, Application global scope
2, Session scope
3, request scope
4, PageContext page scope
Built-in objects
5, Response Response object
6, out output stream object
7, page instance of the current pages object
8, exception exception
9, config Servletconfig/filterconfig object

Priority (depending on the life cycle):
Application > Session > Request > PageContext

Request object:
The request object is an instance of the HttpServletRequest class
Common methods:
String GetParameter (string name)---Returns the value of the parameter specified by name
String[] Getparametervalues (String name)---Returns an array that contains all of the parameter names
void SetAttribute (String, Object)---setting properties in a scope
Object getattribute (String name)---Gets the properties in a scope
String Getrealpath (string path)---Returns the physical path of the passed-in path
String Getcontextpath ()---Returns the context path
String getservername ()---Returns the host name of the requesting server
String getcontenttype ()---Returns the MIME type of the request body
String getprotocol ()---Returns the protocol type and version number of the request
int Getserverport ()---Gets the port number of the server
int getcontentlength ()---Returns the length of the request body (in bytes)
String getremoteaddr ()---Returns the IP address of the client sending this request

Response Object
Response object is an instance of HttpServletResponse
Common methods:
Setcharacterencoding (String name)---Set the character encoding used by the response page
setContentType ("text/html; Charset=utf-8 ")---set (MIME type) Request header
Response.getwriter (). Append (string content)---output a string to a page

Session Object
Session refers to the time when a user enters a Web site to close the browser, the Tomcat server default session time is 30 minutes, that is, open a site for 30 minutes without action, the session object will also expire

Session exists in the server's memory, the server of different users corresponding to the session is also different, so the server is used to determine whether the current logged on the user is the same time need session

Session object is an instance of HttpSession
Common methods:
Long GetCreationTime ()---Returns the time the Session object was created
String getId ()---Returns a sessionid that is unique
void SetAttribute ()---Set a property and a property value
Object getattribute ()---Gets the property value of a property
String[] GetValueNames ()---Gets the property names of all the available properties in the session object as an array
Setmaxinactiveinterval ()---Set how long the session expires (default 30 minutes)
Getmaxinactiveinterval ()---Set the session's expiration time in seconds
Application Object
The Application object is a global object that has a lifecycle of server startup until the server stops, where you can store some global variables

SetAttribute (String, Object)---setting a property and property value
GetAttribute (String)---Get the value of a property
Getattributenames ()---gets all the property names in the Application object

JSP (Java server Page)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.