Java Related Knowledge Review

Source: Internet
Author: User

1, HTTP access mode:

GET, POST, HEAD, DELETE, TRACE, PUT, OPTIONS

Head indicates the query header information, the server returns the file type, length, last modified time and other information, this method is seldom used.

Get methods are commonly used to query information, and submit data cannot exceed 256 characters (the total URL length cannot exceed 255 characters). The content of the query submitted by Java is displayed in the browser address bar.

Post to submit data, the data is not displayed in the browser address bar. The sent command needs to provide the data type and length of the submission. Used to submit form data. There is no limit to the length of content being submitted.

There are two types of data: one is the normal text type (ASCII code data) and the type is "application/x-www-form-urlencoded".

The other is file data (binary data), and the type is "Multipart/form-data".

2. servlet

1) servlet interface: Javax.servlet.Servlet

2) servlet package: javax.servlet.*;javax.servlet.http.*;

The Javax.servlet.http.HttpServlet class has implemented all the methods of the Servlet interface.

3) Configuring the Servlet

<servlet></servlet> the start tag and end tag of the servlet;

The name of the <servlet-name></servlet-name> servlet is required; can be any value, but must be unique in Web. xml

<servlet-class></servlet-class> the class name of the servlet is required;

<init-param></init-param> initialization parameters, including a parameter name <param-name> and parameter values <param-value>

<load-on-startup></load-on-startup> Configure how the servlet is loaded: 1,tomcat automatically loads the servlet;0 at startup, Tomcat loads the servlet the first time the client requests the servlet

<servlet-mapping></servlet-mapping> Configure how servlets are accessed

<servlet-mapping>

<servlet-name></servlet-name>

<url-pattern></url-pattern><!--can configure multiple run wildcard characters "*" and "?" -

</servlet-mapping>

<init-param></init-param> Initialize parameter getinitparameter (String param) to get initialization parameters

<context-param></context-param> context parameters, document parameters

Getservletconfig (). Getservletcontext () to get a ServletContext object, use the Getinitparameter () method of the ServletContext to get the parameters of the specified name. Getinitparameternames () gets all the Context-param parameters.

Resource injection (Resource injection), resource injection

When the server starts, the information configured in Web. XML is automatically injected into the servlet.

Through annotations (Annotation, @Resource), it is a special interface, marked with the "@" symbol.

e.g.:

@Resource (name= "Messagenameinwebxml")

Private String message;

Or

Private @Resource (name= "messagenameinwebxml") String message;

Use <env-entry> in Web. XML to configure resources. You can only configure variables of the standard type under the Java.lang package, such as String, Integer, double, and so on.

But Servlets can inject custom Java beans and complex type variables such as data sources. However, resource injections require server support. Tomcat6 above support.

4) Use Jndi to get resources

Resource injection works by Jndi (Java Naming and directory interface, Java naming and directory Interface). The Injectionservlet instance uses the <env-entry> configuration-related Jndi resource, and then uses @resource to inject the JNDI resource of the specified rank into the Injectionservlet.

Servlet life cycle

Init (ServletConfig conf), Service (servletrequest req, servletrespond Res)->destroy ()

Java Related Knowledge Review

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.