Main components and technologies of Java Web programming-JSP and Java Web programming jsp
References: Lecture 15 on J2EE open-source programming
The JSP (Java Server Page) Page consists of HTML code and the Java code embedded in it.
Simple JSP pages include:
1 JSP pages generally include JSP commands, JSP script elements, JSP standard actions, and JSP implicit objects.
JSP commands
1) page command
Defines some attributes to notify the Servlet engine of JSP settings, mainly as follows:
Language attribute: The scripting language used to compile JSP pages, for example, Java language <% @ page language = "java" %>
ContentType attribute: Response MIME type (multi-purpose Internet Mail Extension type, which is a type of method for setting a file with a certain extension to be opened by an application ),
For example, <% @ page contentType = "text/html; charset = GB2312" %> charset sets the page character type
PageEncoding attribute: Code of the jsp page file, for example, <% @ page pageEncoding = "UTF-8" %>
Difference from contentType property: http://smiky.iteye.com/blog/894938
Import attributes: introduce software packages or classes, such as <% @ page import = "java. io. *; java. util. *" %>
Session attribute: Specifies the availability of JSP page sessions. The default value is true, for example, <% @ page session = "false" %>
IsErrorPage attribute: Specifies whether the current page is used as a JSP error page. The default value is false, for example, <% @ page isErrorPage = "true" %>
ErrorPage attribute: sets the error page. If an unhandled page exception occurs, the page is redirected to this setting page, which can be used with the isErrorPage attribute,
For example: <% @ errorPage = "error. jsp" %>
Example: http://www.tojsp.com/jsp/how-to-use-jsp-error-page.html
2) include command
Specifies the file name (relative path) to be inserted during JSP page compilation. The file content is part of the JSP page. It can be used to insert code that is common to multiple pages,
For example, wrap the header file (header.html) on the jsppage <% @ include file = "header.html" %>
3) taglib (TAG Library) command
Introduce the tag library resources required for this page on the JSP page, for example: <% @ taglib prefix = "s" uri = "/struts-tags" %>
JSP script Element
1) JSP Declaration
Defines JSP page-level variables and methods. Place the statement in <%! In the tag with %>, it always ends with a semicolon, such:
<%!
Private int x = 0;
%>
2) JSP expressions
Insert a value directly to the output, for example, <% = Math. PI %>
3) JSP code segment
Valid code snippets included in the <% and %> tags, such:
1
JSP standard action
1) forward action <jsp: forward>
Submit a request to a different page, for example:
<Jsp: forward page = "another. jsp">
<Jsp: param name = "user" value = "Tom"/>
</Jsp: forward>
<Jsp: param> used to pass additional request parameters. The name attribute specifies the parameter name, and the value Attribute specifies the parameter value.
2) include action <jsp: incluse>
Insert a file to a specific JSP page. This file contains the time when the JSP page is requested, for example:
<Jsp: include page = "one.html" flush = "true"/>
The page attribute specifies the relative path of the page to be included. The flush attribute specifies whether the buffer zone is flushed.
Differences from include commands:
Include command: only static pages or document content can be merged.
Include action: can include dynamically generated output results
3) useBean action <jsp: useBean>
Find and load existing JavaBean, such:
1 <% @ page language = "java" %> 2
The id attribute defines an instance that uniquely identifies the Bean. The class attribute specifies the class of the Bean object to be implemented, and the scope attribute specifies the Bean usage range (page, session, application)
4) JSP implicit object
Some predefined variables contained in JSP expressions and code segments: request, response, out, session, application, config, page, pageContext, and exception.