JSP Data interaction

Source: Internet
Author: User

First, the Java small script in JSP
1.<% Java code Snippet%>
2.<% =java expression%> cannot have a semicolon
3.<%! member variables and function declarations%>
Second, the note
1.<!--HTML comments--the client can see
2.&LT;%--JSP Note--%> Client cannot see
Third, the implementation process of JSP page
1. Client request (enter URL)
2. Server
(1) The JSP is now translated into a. java file (first time request)
If this is a second request and the content of the JSP page does not change
(2) Compiling a Java file into a. class file
(3) Execute the. class file
3. Send the executed results and HTML static content to the client
4. Disconnect the connection
Iv. JSP built-in objects
is an object created by the Web container and can be used directly, without any new
1.out: Method Print (text) outputs content to client
2.request: Client Request Content
Method:
GetParameter ("key") to get the individual data submitted by the client
Getparametervalues ("key") gets multiple data submitted by the client
Setcharacterencoding ("encoding") resolves the garbled post submission method
Getrequestdispatcher ("page"): for page forwarding
3.response: Output content to clients in response to client requests
Method
Sendredirect ("page");//Page redirection
V. The difference between forwarding and redirection
1. Forwarding
A. Server behavior
B. The client only sends a single request
C. Retention of request data, sharing of data between pages
D. The address bar does not change
2. Redirection
A. Client-side behavior
B. 2 requests made by the client
C. Data cannot be persisted and data cannot be shared between pages
D. Change of Address bar
Vi. Sessions: Session
A browser-to-server call (similar to a phone call)
1. The session is one by one corresponding to the browser
2. The same browser different request is a session
3. Different browsers are different sessions
4. Typically used to save client-specific information (temporary)
Session Expiration:
1. In principle, the browser is closed and the session expires (not necessarily in the actual process)
2. Expired Expiration Date
3. Call invalidate (), immediately expire
Method:
SetAttribute (String key,object value), saving data to session
Object GetAttribute (String key) reads data to session
Setmaxinactiveintervals Set Validity period
Invalidate () invalidates the session
RemoveAttribute (String key) removes the specified session
Vii. inlude directive: Include page information on another page (statically included)
<%@ include file= "page"%>
VIII. Application: Application-Level objects
Data shared by individual clients
Method:
SetAttribute (String key, object value)
GetAttribute (String key)
Getrealpath ("virtual path"); Get physical path based on virtual path
Ix. Cookies: Saving information for a specific client
Usage:
1. Create
Cookie Ck=new Cookie (String key,string value)
Ck.setmaxage ("Time"), set the effective time, do not set the default browser is closed when invalid
2. Save
Response.addcookie (CK);
3. Read cookies
A.cookie[]cks=request.getcookies ();
B. Traversal
GetName (): Gets the name of the current cookie (key name)
GetValue (): Gets the value of the current cookie
Ten, the difference between session and Cookie
Session Cookie
Saved in the server's memory on the client's hard disk
Save object Type Save string type
Save temporary data Save permanent data
High security and poor security
Xi. JavaBean
is a Java class
Functionally, Java classes are divided into: business classes and data classes
A Java class that meets the following requirements is JavaBean:
1. is a public class
2. Public construction methods with or without parameters
3. Property private: First letter lowercase
4. Getter and Setter methods
(Method name format: Get property name (uppercase), set property name (uppercase))
12. Built-in Object supplement
1.pageContext: Information during the current page execution
2.page: Current JSP page
3.config: Configure JSP page initialization data
4.exception: Exception
13. Four scopes (scope of action)
1.page: Current Page
2.request: Request the same request at a time
3.session: Same Client
4.application: The entire application
14. The file contains
1.include directive: <%@ include file= "page"%>
Static include: Copies the contents of the specified page to another page, and then executes
2.include method: Pagecontext.include ("page")
Dynamic inclusion: Executes the page dynamic code first, and then contains the result and static code to another page
The value of the transfer between pages
1.form table only son values
2.session Transmit Value
3. Via hyperlinks (like form form get submissions)
Url? Keyname= value 1 &keyname= value 2

JSP Data interaction

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.