Java basic knowledge Records--java Web section (excerpt from Zhang Xiaoxiang:) __java

Source: Internet
Author: User
         

1.tomcat Experience in optimization

Remove the monitoring of web.xml, and edit the JSP into a servlet in advance.

With excess physical memory, increase the memory of the JVM used by Tomcat.

2.HTTP the difference between the get and post methods of the request:

HTTP defines the different methods of interacting with the server, the most basic method of Get and post.

Difference:

1.get gets the data from the server, and the post is to transfer the data to the server.

2. Get is to add the parameter data queue to the URL of the action attribute that submits the form, and the value corresponds to each field one by one in the form, which can be seen in the URL. Post is a httppost mechanism that places the fields in the form and their contents in the HTML header to the URL address known to the action attribute. This process is not visible to the user.

3. For Get way, server end use request. QueryString gets the value of the variable, and for the Post method, the server ends with request. form to obtain the submitted data.

4.get transmits a small amount of data, not greater than 2KB. Post transfers have a large amount of data, which is generally default to unrestricted. In theory, however, the maximum number of IIS4 is 100KB in 80kb,iis.

5.get security is very low and post security is high.

3. Explain what a servlet is

The servlet has a good life-cycle definition, including loading and instantiating, initializing, processing requests, and service completion. This lifetime is expressed by the init,service and destroy methods of the Javax.servlet.Servlet interface.

4. Say a servlet's lifecycle:

When the servlet is instantiated by the server, the container runs its Init method, the service method is run when the request arrives, and the service method automatically dispatches the Doxxx method (Doget,dopost) corresponding to the request. Call its Destroy method when the server decides to destroy the instance.

The Web container loads the servlet, and the lifecycle begins. The servlet initialization is done by invoking the Init () method of the servlet. By invoking the service () method, the different DOXXX methods are invoked depending on the request. End service, the Web container invokes the servlet's Destroy () method.

5. The basic architecture of the servlet

public class Servletname extends httpservlet{

public void DoPost (httpservletrequest request,httpservletresponse response)

Throws servletexception,ioexception{}

public void doget (HttpServletRequest request,httpservletresponse response) throws

servletexception,ioexception{}

}

6. Forward () differs from redirect () in the Servlet API:

Forward () is the control in the container of the steering, in the client browser address bar will not show the turn of the address, the latter is a complete jump, the browser will get the address of the jump, and resend the request link. In this way, you can see the link address after the jump from the address bar of the browser. So, the former is more efficient, when the former can meet the need, try to use the forward () method, and it also helps to hide the actual link. In some cases, for example, you need to jump to a resource on a different server, you must use the Sendredirect () method.

7. What circumstances invoke Doget () and Dopost ()?

The method property in the form label in the JSP page is called doget () on Get and called Dopost () for post.

8. Main methods of the Request object:

SetAttribute (String name,object): Sets the parameter value of the request named name

GetAttribute (String name): Returns the property specified by name

Getattributename (): Returns a collection of the names of all properties of the request object, with the result being an instance of an enumeration

GetCookies (): Returns all cookie objects for the client, resulting in an array of cookies

Getcharacterencoding (): Returns the character encoding method in the request

Getcontentlength (): Returns the length of the requested body

GetHeader (String name): Get file header information for HTTP protocol definitions

Getheasers (String name): Returns all values for the request header of the specified name, with the result being an instance of an enumeration

Getheadernames (): Returns all names with the request header, and the result is an enumeration of instances

getInputStream (): Returns the requested input stream, which is used to obtain the data in the request

GetMethod (): Get client to server-side data transfer method

GetParameter (String name): Gets the parameter value specified by name on the client delivery server side

Getparameternames (String name): Gets the name of all the parameters that the client passes to the server side, and the result is an instance of an enumeration

Getparametervalues (String name): Gets all values that have the parameters specified by name

Getprotocol (): Gets the protocol name on which the client transmits data to the server side

GetQueryString (): Get query string

Getrequesturi (): Gets the client address that issued the request string

GETREMOTEADDR (): Get the IP address of the client

Getremotehost (): Get the name of the client

GetSession ([Boolean create]): Return and request related session

getServerName (): Get the name of the server

Getservletpath (): Gets the path to the script file requested by the client

Getserverport (): Get the port of the server

RemoveAttribute (String name): Delete a property in the request

9. The difference between forward and redirect:

Forward is the server request resources, the server directly access the URL of the destination address, the corresponding content of the URL read over, and then send the content to the browser, the browser does not know where the server sent the content from, so its address bar or the original address.

Redirect is the server based on logic, send a status code, tell the browser to request that address again, generally speaking, the browser will use the parameters just requested again, so the session request parameters can be obtained.

What are the built-in objects for JSP? What the difference is. What are the ways to separate.

JSP has the following 9 built-in objects:

Request: Client requests, this request contains parameters from the Get/post request

Response: Web page Returns the response of the client

PageContext: The properties of the Web page are managed here

Sessions: Session duration associated with the request

What the Application:servlet is doing

Out: Output used to transmit a response

Config:servlet Frame Parts

PAGE:JSP Web page itself

Exception: For error pages, exceptions for capture

Request represents a HttpServletRequest object. It contains information about browser requests and provides several useful methods for obtaining cookie,header and session data.

Response represents the HttpServletResponse object and provides several methods for setting the response to the browser (such as cookies, header information, etc.)

An Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser.

PageContext represents a Javax.servlet.jsp.PageContext object. It is an API for easy access to a wide range of namespaces, servlet-related objects, and a way of wrapping common servlet-related functionality.

The session represents a requested Javax.servlet.http.HttpSession object. Session can store the user's state information.

Application represents a Javax.servlet.ServletContext object. This helps you find information about the servlet engine and servlet environment.

Config represents a Javax.servlet.ServletConfig object. This object is used to access the initialization parameters of the servlet instance.

Page represents a servlet instance that is generated from this page.

One. JSP has those actions. What the difference is.

JSP has a total of the following 6 basic actions:

Jsp:include introduces a file when the page is requested

Jsp:usebean Find or instantiate a JavaBean

Jsp:setproperty to set JavaBean properties

Jsp:getproperty to output a JavaBean property

Jsp:forward the request to a new page

Jsp:plugin generates object or embed tags for Java plug-ins based on browser type

Common commands for JSP

Iserrorpage (whether the exception object can be used), iselignored (whether the expression is ignored)

The difference between dynamic include and static include in JSP

Dynamic include using jsp:include actions to implement <jsp:include page=include.jsp flush=true/> It always checks for changes in the contained files, suitable for inclusion of dynamic pages, and can take parameters.

Static include is implemented with include pseudo code, does not check the changes of the contained file, apply to contain static page <%@ include file=included.html%>

14. Methods for passing objects between pages:

Request session Application Cookies, etc.

What are the similarities and differences between 15.jsp and servlet, and what are their connections?

JSP is an extension of the servlet technology, which is essentially a simple way for the servlet to emphasize the outward expression of the application. JSP is compiled "class servlet". The main difference between a servlet and a JSP is that the application logic of the servlet is in the Java file and is completely detached from the HTML in the presentation layer. In the case of JSP, Java and HTML can be combined into a file with a. jsp extension. The JSP focuses on views, and the servlet is primarily used for logical control.

What technologies are available for each part of MVC. How to achieve it.

MVC is shorthand for Model-view-controller, model represents the Applied business logic (implemented through JAVABEAN,EJB components), View is the application's representation (generated by JSP pages), The controller is a process control (typically a servlet) that provides the application that divides the application logic, processing, and display logic into different component implementations through this design model. These components can be used for interaction and reuse.

17. We often encounter in the Web application development process

Output some encoded character, such as Iso8859-1, and how to output a string of some kind encoded.

public string translate (string str) {

String tempstr= "";

try{

Tempstr=new String (str.getbytes ("iso-8859-1"), "GBK");

Tempstr=tempstr.trim ();

}catch (Exception e) {

System.err.println (E.getmessage ());

}

return tempstr;

}

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.