JSP basic syntax

Source: Internet
Author: User
Tags config flush int size locale object object reset stack trace throwable

One, JSP elements

1, script elements, including expressions, code fragments (including built-in classes), declarations (member variables and methods), annotations (output and shadowing)

2, the instruction element, including page (Language,extends,import,session,buffer,autoflush,isthreadsafe,info,errorpage,iserrorpage, ContentType), include (file), and Taglib (Uri,prefix).

3, action elements, system elements:

Jsp:include page=? Flush= "true" (jsp1.1 must be This) can be entrained jsp:param to add request

Jsp:forward page=? Can be jsp:param to add request

Jsp:param name=? Value=?

Jsp:plugin

Type= "Bean|applet"

Code= "Classfilename"

Codebase= "Classfilepathurl"

Align=?height=? Name=? Width=?hspace= "The size of the horizontal white space between the wrapping text" Vspace=?

Archive= "Identifies the URL of the. jar file for the Java class containing the object"

Jrevision= "identifies the runtime environment JRE version required by the component, default 1.1"

Title= "object title used by IE"

Nspluginurl= "The URL of the JRE plugin can be downloaded for Netscape"

Iepluginurl= "The URL of the JRE plugin can be downloaded for IE"

Jsp:params by Jsp:plugin encapsulated a jsp:action list like Jsp:param placed in the middle

Jsp:fallback load Jsp:plugin is used to provide an alternate HTML response, such as a piece of text

Jsp:usebean

Id= "Instance Name"

Scope= "Page|request|session|application"

Class= "class name, if there is no type must have class, if there is beanname must not class"

Beanname= "a.b.c|a/b/c.cer, not incompatibility with class"

Type= "has the class name of the interface, or the name of the interface implemented by the class (can only use methods in the interface)"

Jsp:setproperty name= "Bean instance ID" property= "bean must have Setpropertyname () method" [param=?] value=? If you do not specify value, take a variable from request with the same name or param name, if the value is "" does not execute

Jsp:getproperty name= "Bean id" property= "Bean property, must have Getpropertyname () method" The action element directly outputs

4, white space character: space (0x20), Tab (0x09), carriage return (0x0d0a), these symbols in the JSP page will be out.println

5, escape character%>,,%>, ', ' should be escaped

Two, hidden objects

1,request javax.servlet.HttpServletRequest Type,

String GetParameter (string parametername);

Java.util.Enumeration Getparamerternames ();

String[] Getparametervalues ();

Object getattribute (String name);

Java.util.Enumeration Getattributenames ();

void RemoveAttribute (String attributename);

void SetAttribute (String name, object);

Javax.servlet.http.cookie[] GetCookies ();

Java.util.Enumeration getheadernames ()/message header

Java.util.Enumeration getheaders (String headername);

String GetHeader (string headername);

int Getintheader (String headername);

Long Getdateheader (String headername);

String GetMethod ();//Request method

String getrequesturi;//between the protocol name and the query string, no host name

String Getcontextpath ()//The application environment in which the requested file resides

String Getservletpath ();//ContextPath as root, specifying where the applet or JSP resides

String pathinfo ()//additional path information

String getquerystring ();

Boolean issecure ()//whether HTTPS is used

Boolean Isrequestedsessionidfromcookie ();

Boolean Isrequestedsessionidfromurl ();

Boolean isrequestedsessionidvalid ()//The ID of the request session is valid

Java.util.Locale GetLocale ()//The customer agrees that the content taken by the Locale depends on the Acceptlanguge

Java.util.Enumeration Getlocales ();

2,response Javax.servlet.http.HttpServletResponse

int getbuffersize ();

void setbuffersize (int size);//

Boolean iscommitted ()//The response has been committed after writing the status code and header

void reset ()//purge all data in the cache including status codes and headers

void Flushbuffer ();//force any content in the cache to be written to customer

void AddHeader (String name,string value);

void SetHeader (string name, string value);

void Adddateheader (String name, long date);

void Setdateheader (String name, long date);

void Addintheader (String name, int value);

void Setintheader (String name, int value);

Boolean Containsheader (String name);

void setContentType (String type);

void SetLocale (Java.uti.Locale, Locale);

void Senderror (int sc, String msg);

void Senderror (int sc);//Status code and descriptive information item the customer sends an error response

void Sendredirect (String location);

3,pagecontext Javax.servlet.jsp.PageContext (materialized by specific developers)

/*int Scope:

Pagecontext.page_scope

Pagecontext.request_scope

Pagecontext.session_scope

Pagecontext.application_scope

*/

Object getattribute (String name);//pagescope variable

Object getattribute (String name, int scope);

Object Findattribute (String name);

Java.util.Enumeration getattributenamesinscope (int scope);

int Getattributescope (String name);

void RemoveAttribute (String name);

void RemoveAttribute (String name, int scope);

void SetAttribute (String name, object);

void SetAttribute (String name, object object, int scope);

Javax.servlet.jsp.JspWriter getout ();//out

Exception getexception ();//exception

Javax.servlet.ServletRequest getrequest ();//request

Javax.servlet.ServletResponse GetResponse ();//response

Javax.servlet.http.HttpSession getsession ();//session

Javax.servlet.ServletConfig getservletconfig ();//config

Javax.servlet.ServletContext Getservletcontext ();//application

Javax.servlet.jsp.JspWriter Popbody ();

Javax.servlet.jsp.tagext.BodyContent pushbody ();//manage nested output streams within taglib

void forward (String relativeurlpath);

void include (String relativeurlpath);

void HandleException (Java.lang.Exception e);

4,session javax.servlet.http.HttpSession

Install cookies

URL Rewrite

SSL session

Object getattribute (String attributename);

Java.util.Enumeration Getattributenames ();

void SetAttribute (String name, Object value);

void RemoveAttribute (String name);

Long Getlastaccessedtime ()//time of last send related data for this session

/* About long time: refers to the number of milliseconds starting from 1970-1-1 00:00:00 * *

void setmaxinactiveinterval (int interval);//sec

int Getmaxinactiveinterval ();

void invalidate ();//Make session invalid

5,out Javax.servlet.jsp.JspWriter

Errors can cause java.io.IOException

void clear ();//purge buffer, Response.reset ()?

void Clearbuffer ();//Clear Buffer Current Contents

void Flush ();//

void Close ()//refresh before closing

int getbuffersize ();

int getremaining ()//Buffer not used

Boolean Isautoflush ();//page AutoFlush Property

void print (object);

void println (Object object);

6,application Javax.servlet.ServletContext

String Getinitparameter (string name);

Java.util.Enumeration Getinitparameternames ();

Object getattribute (String name);

void Setattibute (String name, object);

Java.util.Enumeration Getattributenames ();

void RemoveAttribute (String name);

When modified, the IsThreadSafe is best set to false, and with synchronized ()

Java.net.URL getresource (String path);

Url::getpath () is the same as Application.getrealpath ()

Java.io.InputStream getResourceAsStream (String path);/with Url::openstream ();

RequestDispatcher: Work in service between the server Laughing program

Javax.servlet.RequestDispatcher Getnameddispatcher (String name);//name is the name of the servlet

Javax.servlet.RequestDispatcher getrequestdispatcher (String path);//path as the path to the servlet

void log (String message);

void log (String message, throwable throwable);//Log a messages and stack trace to a small program log file

String GetMimeType (string file);

String Getrealpath (string virtualpath);//url::getpath

String Getserverinfo ();

int getmajorvertion ();

int getminervertion ();

7,config Javax.servlet.ServletConfig

String Getinitparameter (string name);

Java.util.Enumeration Getinitparameternames ();

String Getservletname ();

ServletContext Getservletcontext ();

8,page Javax.servlet.jsp.HttpJspPage

is not usually used by the creator of the JSP page

Javax.servlet.ServletConfig Getservletconfig ();

String Getserveletinfo ();

9,exception java.lang.Exception

String Getlocalizedmessage ();

String GetMessage ();

void Printstacktrace ();

void Printstacktrace (Java.io.PrintStream PS);

void Printstacktrace (Java.io.PrintWriter pw);

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.