Java Knowledge Summary-4

Source: Internet
Author: User

Servlet Scopes

Page

Refers to the current page, which is valid in a JSP page

Request

Refers to the entire process of returning a response from the HTTP request Path server processing end

Session

Valid range current session, never browser open to browser close process

Application

Its effective range is the entire application

Common methods in request and their functions

1.getParameter (name) method

2.getParameterValues (String name) method

3.getParameterNames method SetAttribute (String name,object): Sets the parameter value of the request named name

GetAttribute (String name): Returns the property value specified by name;
Request.setcharacterencoding ("UTF-8");

Common methods and their functions in response

Response commonly used properties are: Buffer property, expires property, CharSet property, ContentType property, ExpiresAbsolute property.
Response commonly used methods are: 1. Wite method: The data is sent to the customer-service browser. 2. Redirect method: Causes the browser to redirect to the URL address specified by the program. 3.Clear method: You can clear all HTML output from the buffer. 4.End method: Cause the Web server to stop processing the script and return the current results


Doget ()


Handling GET Requests

Get is fetching data from the server

The amount of data transferred by get is limited in size

Low security

Better execution efficiency than post

DoPost ()

Handling GET Requests

Transferring data to the server

Unlimited Transfer data size

High safety

Init ()

Destroy ()

Servlet configuration

<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>moreservlets. Testservlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/UrlTest</url-pattern>
</servlet-mapping>

Forwarding and redirection

redirect

Resp.sendredirect ("success.jsp");

Forward

Req.getrequestdispatcher ("success.jsp"). Forward (req, resp);

Difference

1. Forwarding is done on the server side; redirection is done by the client

2. Fast forwarding speed and slow redirection

3. The same request is forwarded; Redirects are two or more different requests

4. Forwarding does not execute post-forwarding code; REDIRECT executes code after redirection

5, the forwarding address bar has not changed; REDIRECT Address bar changes

6. The forwarding must be done under the same server; redirection can be done under different servers

Life cycle

1. Instantiation via Tomcat

2. Initialize phase call init () method This method only executes once

3. Call the Service () method in response to the request business phase This method can perform multiple

4. Terminate phase call Destroy () method This method only executes once

Json

Son is a data structure that replaces XML, which is smaller than XML, and because of its compactness, the network transmits data to reduce more traffic to speed up.

JSON is a string of strings except that the elements are labeled with a particular symbol.

{} Double brackets represent objects

[] brackets represent the array

"" In double quotes is a property or value

: A colon indicates that the latter is a value (the value can be a string, a number, or another array or object)

Gson

ToJson ()

Object to String

Fromjson ()

String to Object

Jsonobject

Put ()

Jsonarray

Put ()

--SRC: Basic storage. Java and some files like Struts.xml.
--web-root: Deploying a Web project is the deployment of this file.
--web-root under Web-inf: There is a Lib folder below to store the jar package. A. class file that contains the page (jsp/html) and. Java generated.

Java Knowledge Summary-4

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.