JSP basic syntax

Source: Internet
Author: User

I. JSP Elements

1. script elements, including expressions, program code snippets (including built-in classes), declarations (member variables and methods), comments (output and hidden)

2. Command elements, including page (language, extends, import, session, buffer, autoFlush, isThreadSafe, info, errorPage, isErrorPage, contentType), include (file), and taglib (uri, prefix ).

3. Action elements and system elements:

Jsp: include page =? Flush = "true" (jsp1.1 must be the same) You can include jsp: param to add a request.

Jsp: forward page =? Jsp: param can be included to add a request

Jsp: param name =? Value =?

Jsp: plugin

Type = "bean | applet"

Code = "classfileName"

Codebase = "classfilePathUrl"

Align =? Height =? Name =? Width =? Hspace = "the size of the horizontal blank space between and the surrounding text" vspace =?

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

Jrevision = "identifies the runtime environment JRE version required by the component. The default value is 1.1"

Title = "title of the object used by ie"

Nspluginurl = "the JRE plug-in URL can be downloaded for Netscape"

Iepluginurl = "you can download the JRE plug-in URL for IE"

Jsp: params a jsp: action List encapsulated by jsp: plugin, such as jsp: param in the middle

When jsp: fallback fails to load jsp: plugin, it is used to provide an alternative 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, there must be class, and if there is beanName, there must be no class"

BeanName = "a. B. c | a/B/c. cer, which is different from the class"

Type = "class name with the same interface, or interface name implemented by the class (only methods in the interface can be used )"

Jsp: setProperty name = "bean instance id" property = "bean must have the setPropertyName () method" [param =?] Value =? If no value is specified, the variable with the same property name or param name is obtained from the request. If the value is "", no execution is performed.

Jsp: getProperty name = "bean id" property = "bean property, must have the getPropertyName () method" this action element is directly output

4. Blank characters: space (0x20), Tab (0x09), and press enter (0x0d0a). All the symbols on the jsp page will be out. println

5. escape characters %>, %>, ', and "should all be escaped.

2. Hide 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 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; // There is no host name between the Protocol name and the query String

String getContextPath (); // application environment where the requested file is located

String getServletPath (); // use contextPath as the root to specify the location of the applet or jsp

String PathInfo (); // additional path information

String getQueryString ();

Boolean isSecure (); // whether HTTPS is used

Boolean isRequestedSessionIdFromCookie ();

Boolean isRequestedSessionIdFromURL ();

Boolean isRequestedSessionIdValid (); // whether the ID of the Request session is valid

Java. util. Locale getLocale (); // the Locale for the content agreed by the customer, depending on AcceptLanguge

Java. util. Enumeration getLocales ();

2, response javax. servlet. http. HttpServletResponse

Int getBufferSize ();

Void setBufferSize (int size );//

Boolean isCommitted (); // whether the response has been submitted after the status code and header are written

Void reset (); // clear all the data in the cache, including the status code and header.

Void flushBuffer (); // force any content in the cache to be written to the 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. UI. Locale, locale );

Void sendError (int SC, String msg );

Void sendError (int SC); // status code and descriptive information items the customer sends an error response

Void sendRedirect (String location );

3. pageContext javax. servlet. jsp. PageContext (specific to the developer)

/* Int scope:

PageContext. PAGE_SCOPE

PageContext. REQUEST_SCOPE

PageContext. SESSION_SCOPE

PageContext. APPLICATION_SCOPE

*/

Object getAttribute (String name); // pagination 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 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 the nested output stream in taglib

Void forward (String relativeUrlPath );

Void include (String relativeUrlPath );

Void handleException (java. lang. Exception e );

4. session javax. servlet. http. HttpSession

// Install cookie

// URL rewriting

// SSL session

Object getAttribute (String attributeName );

Java. util. Enumeration getAttributeNames ();

Void setAttribute (String name, Object value );

Void removeAttribute (String name );

Long getLastAccessedTime (); // The time when the session-related data was last sent

/* About long time: the number of milliseconds that have elapsed since 00:00:00 */

Void setMaxInactiveInterval (int interval); // The unit is seconds.

Int getMaxInactiveInterval ();

Void invalidate (); // invalidate the session

5. out javax. servlet. jsp. JspWriter

// The error is caused by java. io. IOException.

Void clear (); // clear the buffer, response. reset ()?

Void clearBuffer (); // clears the current content of the buffer.

Void flush ();//

Void close (); // refresh before closing

Int getBufferSize ();

Int getRemaining (); // buffer not used yet

Boolean isAutoFlush (); // page autoFlush attribute

Void print (Object 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 object );

Java. util. Enumeration getAttributeNames ();

Void removeAttribute (String name );

// Set isThreadSafe to false and use synchronized ()

Java.net. URL getResource (String path );

// URL: getPath () is the same as application. getRealPath ().

Java. io. InputStream getResourceAsStream (String path); // same URL: openStream ();

// RequestDispatcher

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

Javax. servlet. RequestDispatcher getRequestDispatcher (String path); // path indicates the servlet path.

Void log (String message );

Void log (String message, Throwable throwable); // records a message and stack trace to the applet 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

// Usually not 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.