Servlet's request and response

  SERVLET API in the forward () and redirect () the difference? 

Answer : the former is only the steering control of the container, the client browser's address bar does not show the address after the shift; the latter is complete Jump, the browser will be Jump address, and re send request link. In this way, you can see the link after the jump address from the address bar of your browser. Therefore, the former more efficient and meet the needs in the former, try to use forward () method, and, this also helps hide the actual link. In some cases, for example, you need to jump to an other resources on the server, you must use sendRedirect () method.

 

  Under what circumstances call doGet () and doPost () ? 

Jsp page FORM tag's method attribute to get called when the doGet () , for the post called when doPost () .

 

 

  Request main object method: 

setAttribute (String name, Object) : Set the name for the name of the request parameter values

the getAttribute (String name) : Returns the name specified attribute value

getAttributeNames () : Returns the request object is a collection of the names of all the properties, the result is an enumeration of instances

the getCookies () : all returned to the client Cookie objects, the result is a Cookie array

getCharacterEncoding () : returns the requested character encoding

getContentLength () : returns the requested Body length

getHeader (String name) : get HTTP header information protocol definition

getHeaders (String name) : Returns the name of the request Header of all values, the result is an enumeration of instances

getHeaderNames () : returns so request Header name, the result is an enumeration of instances

the getInputStream () : returns the input stream request for obtaining data request

getMethod () : get the client Method to transmit data to the server

the getParameter (String name) : get the client are transmitted to the server name parameter value specified

getParameterNames () instances to obtain the names of all the parameters of the client to the server side, the result is an enumeration:

GetParameterValues (String name) : get there name all the values of the parameters specified

getProtocol () protocol to obtain the name of the client to transmit data to the server is based on:

getQueryString () : get the query string

getRequestURI () : Get the requesting client address string

getRemoteAddr () : get the client's IP address

getRemoteHost () : get the client's name

the getSession ([Boolean Create]) : Returns associated with the request Session

getServerName () : Gets the server name

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

getServerPort () : Gets the server port number

removeAttribute (String name) an attribute deletion request:

 

 

  forward and redirect differences 

  forward a request to the server resources, direct access to the target server address URL , put the URL response content to read over, and then put these elements and then distributed to the browser, the browser does not know the content sent by the server is going to come from, so it's the address bar or the original address.

     redirect is a server based on logic , send a status code , telling the browser to re-request the address, in general, the browser will just re-request with all the parameters of the request, so the session, request parameters can get.

 

  request.getAttribute () and request.getParameter () What's the difference ?

 

1, getAttribute represents obtain property settings range from a request, you must first set the setAttribute property to be acquired by getAttribute, and get set for the object type Object

 

2, getParameter represents receiving parameters, parameter parameter for the page is submitted, including: parameter form submission, URL rewriting (? Xxx is the 1 id id =) parameter passed and so on, so this method does not set parameters (not setParameter), and the received parameters not return Object, but type String

 

  jsp which have built-in objects ? What role are ? Is there any way were? 

JSP total of the following 9 built-in objects:

request the client request, which contains from GET / POST request parameters

response page returns a response to the client's

pageContext property management page is here

session related to the request of the session

application servlet content being executed

out for the transmission output response

config servlet framework member

page JSP page itself

exception for error pages, uncaught exception

request represents the HttpServletRequest object. It contains information about the browser requests and provides several used to obtain cookie, header, and session useful method of data.

   response represents HttpServletResponse object, and provides several methods for setting response back to the browser (e.g., Cookies, header information, etc.)

   out target is javax.jsp.JspWriter an instance of, and provides several ways so that you can be used to send output back to the browser.

   pageContext represents a javax.servlet.jsp.PageContext object. It is used to facilitate access to a diverse range of namespace, servlet objects associated the API , and packaged generic servlet RELATED function.

   session represents a request javax.servlet.http.HttpSession object. Session can store status information of the user

   applicaton represents a javax.servle.ServletContext object. This helps to find information about servlet engine and servlet information environment

   config represents a javax.servlet.ServletConfig object. This object is used to access the servlet initialization parameters instance.

   page represents a page generated from the servlet instance

 

 

   jsp What action have ? What role are ? 

(The problem seems unimportant, do not understand why there is this question)

JSP: the include : the introduction of a file when the page is requested.

JSP: useBean : Find a instantiate or the JavaBean .

JSP: setProperty : set the JavaBean properties.

JSP: getProperty : output of a JavaBean property.

JSP: Forward : the request to a new page.

JSP: plugin : according to the type of browser Java Generation Plug OBJECT or EMBED tag

 

  JSP 's common commands 

isErrorPage ( whether using Exception objects ) , isELIgnored ( whether or not ignore expressions )

 

 

  JSP dynamic INCLUDE static INCLUDE difference? 

A: Dynamic INCLUDE with jsp: include implementing an action

<jsp: include page = included.jsp flush = true /> it always checks changes contained in the document, suitable for containing dynamic pages, and may be static parameters INCLUDE used include pseudo code , a given does not check with file changes, applicable to contain static pages <% @ include file = included.htm% >

 

 

  What are the two ways are the jump ? What is the difference ? 

<jsp:include page=included.jsp flush=true>

<jsp:forward page= nextpage.jsp/>

The former will not turn pages include pages referred to, simply display the results page, the main page or the original page. After the implementation will come back, the equivalent of function calls. And you can take parameters . The latter completely turned a new page and never return. Equivalent to go to the statement.

  Method object passed between pages 

requestsessionapplicationcookie

 

 

  JSP and Servlet What are the similarities and differences What is the connection between them is? 

JSP is Servlet extension technology, is essentially Servlet simple way, and more emphasis on the appearance of the application of the expression. JSP compiled a " class the servlet" . Servlet and JSP main difference is that, Servlet application logic in Java file, the presentation layer and completely from the HTML separated inside. The JSP situation is Java and HTML can be combined into a single extension .jsp file. JSP focuses on view, the Servlet mainly for control logic.

 

 

  MVC various parts of all those technologies to achieve ? How to achieve ? 

MVC is the Model - View - the Controller shorthand. Model represents the business logic of the application (via the JavaBean , the EJB component implementation), View is a surface application (from the JSP to generate a page), the Controller is to provide a process control application (typically a the Servlet ), such a design model the application logic, processing and display logic implemented into different components. These components can interact and reuse.

Guess you like

Origin www.cnblogs.com/zxx7777777/p/11653154.html