JSP Foundation

1. Pass data from servlet to JSP:

In servlet:

RequestDispatcher req = request. getRequestDispatcher("NewFile.jsp");

String name = "test";

request. setAttribute("name",name);

req. forward(request,response);

In JSP (/ webcontent / newfile. JSP file): <%

out. println("test:" + request.getAttribute("name"));

%>

2. JSP statement:

A declaration statement can declare one or more variables and methods for later java code. In the JSP file, you must declare these variables and methods before you can use them.

3. JSP expression:

A script language expression contained in a JSP expression is first converted into a string and then inserted where the expression appears. The expression element can contain any expression that conforms to the Java language specification, but you cannot end the expression with a semicolon.

4. JSP comments

5. JSP instruction

JSP instructions are used to set attributes related to the entire JSP page.

<%@ page ... %>: Define the dependent properties of the page, such as scripting language, error page, cache requirements, and so on

The page instruction provides instructions for the container to use the current page. A JSP page can contain multiple page instructions.

<%@ include ... %>: Include other files

JSPS can include other files through the include directive. The included files can be JSP files, HTML files or text files. The included file is like a part of the JSP file and will be compiled and executed at the same time.

<% @ taglib...% >: introduce the definition of label library, which can be user-defined labels

JSP API allows users to customize tags. A custom tag library is a collection of custom tags.

The taglib instruction introduces the definition of a custom tag set, including library path and custom tag.

6. JSP behavior

JSP behavior tags use XML syntax structures to control the servlet engine. It can dynamically insert a file, reuse JavaBean components, guide users to another page, generate relevant HTML for Java plug-ins, and so on.

Jsp: include is used to include static or dynamic resources in the current page

Jsp: usebean finds and initializes a JavaBean component

Jsp: setproperty sets the value of the JavaBean component

Jsp: getproperty inserts the value of the JavaBean component into the output

Jsp: forward passes a request object containing user requests from one JSP file to another

Jsp: plugin is used to include applet and JavaBean objects in the generated HTML page

Jsp: element dynamically creates an XML element

Jsp: attribute defines the attributes of dynamically created XML elements

Jsp: body defines the body of dynamically created XML elements

Jsp: text is used to encapsulate template data

7. JSP implicit object

Request: an instance of the HttpServletRequest class

Response: an instance of the httpservletresponse class

Out: an instance of the printwriter class, which is used to output the results to the web page

Session: an instance of the httpsession class

Application: the instance of ServletContext class, which is related to the application context

Config: an instance of the ServletConfig class

Pagecontext: an instance of pagecontext class, which provides access to all objects and namespaces of JSP pages

Page: similar to this keyword in Java class

Exception: the object of exception class, which represents the corresponding exception object in the JSP page where the error occurred

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>