Interview eight

The difference between the JSP include dynamic and static include the?

With dynamic include jsp: include ... / operation instructions, and suitable for containing dynamic pages, and can be parameterized. Not be introduced include dynamic compiler directives include the page, will only be introduced into the present insertion body page content of the page.

Static include using <% @ include file = included.htm%> compilation instructions.

Dynamic and static import to import the following three differences:

  1. Static introduced is introduced completely into code pages, two pages into a seamless Servlet; to introduce dynamic content is introduced is introduced include a method using a page in a Servlet.

  2. Will work when the static import import page compiler directives; is introduced into a dynamic page when importing compiler directives are useless, just insert body content is imported page.

  3. It may also contain additional dynamic parameters.

What action instruction JSP there?

JSP have the following main operation command 7:

jsp: forward: performing page turning, the processing of the request is forwarded to the next page.

jsp: param: used to pass parameters to be used in conjunction with other label support parameters.

jsp: include: a dynamic includes a JSP page.

jsp: plugin: Applet or JavaBean for download to the client execution.

jsp: useBean: create an instance of a JavaBean.

jsp: setProperty: set property values ​​JavaBean instance.

jsp: getProperty: output JavaBean instance attribute value.

Which have built-in objects JSP? What role are?

JSP total of the following nine built-in objects: nine built-in object in turn below.

  1. file application : javax.servlet.ServletContext example, the Web application itself on behalf of the instance belongs JSP, JSP pages can be used, or the exchange of information between Servlet. Commonly used methods are getAttribute (String attName), setAttribute ( String attName, String attValue) and getInitParameter (String paramName) and the like.

  2. config : javax.servlet.ServletConfig example, which is the representative example of the configuration information of the JSP. There getInitParameter (String paramName) and getInitParameterNames () method and the like commonly used method. In fact, JSP page is usually no need to configure, configuration information does not exist. Thus, the object is more effective in a Servlet.

  3. Exception : The java.lang.Throwable example, the instance on behalf of other pages of exceptions and errors. Only when the page is error handling page, that page of compiler directives isErrorPage property is true, the object can be used. Commonly used methods are getMessage () and printStackTrace () and the like.

  4. OUT : javax.servlet.jsp.JspWriter example of the JSP page instance representing the output stream, for outputting the contents, is formed HTML page.

  5. Page : The page on behalf of itself, usually without much use. I.e. in the this Servlet, which is generated by the Servlet class type, where you can use the page with this.

  6. the pageContext : javax.servlet.jsp.PageContext example of the object on behalf of the JSP page context, the use of the object can access the shared data page. Commonly used methods are GetServletContext () and getServletConfig () and the like.

  7. Request : javax.servlet.http.HttpServletRequest example, which object encapsulates a request, the client request parameters have been encapsulated in the object. It is a common object, retrieving the client request parameters must use the object. Commonly used methods are getParameter (String paramName), getParameterValues ( String paramName), setAttribute (String attrName, Object attrValue), getAttribute (String attrName) and setCharacterEncoding (String env) and the like.

  8. Response : Examples javax.servlet.http.HttpServletResponse response on behalf of the server to the client. Normally rarely used direct response to the object, but the use of out unless the need to generate non-character response. Commonly used in the redirect response object, commonly used methods are getOutputStream (), sendRedirect (java.lang.String location ) and the like.

  9. the session : javax.servlet.http.HttpSession example of the object represents a session. When a client browser to establish a connection to the site, the session starts; when the client closes the browser session ends. Commonly used methods are: getAttribute (String attrName), setAttribute (String attrName, Object attrValue) and the like.

What are the similarities and differences between JSP and Servlet have?

JSP is the essence of Servlet, JSP Web server after compiling it into a Servlet, so their life cycle, the operating mechanism is completely identical.

Servlet and JSP major difference is the manifestation: Servlet is a Java class inherited HttpServlet, and JSP is the JSP script embedded in an HTML page, a page named .jsp file extension combined into after embedding.

In the actual project in development, JSP focuses on view, Servlet mainly for control logic.

Difference request.getParameter () and request.getAttribute () is?

getParameter () request for acquiring parameters, request.getAttribute () request for acquiring the attribute. Specifically, there is a difference between them.

  1. getParameter () Gets the type is String; getAttribute () Get the type Object

  2. getPrameter () Gets the value of the parameter is POST / GET request; and getAttribute () Gets the request scope attribute - i.e. request.setAttribute () Set the attributes. The request did not like request.setParamter method.

  3. setAttribute () is to put the object in the Web server corresponding to a page of the memory, when the page to another page forward into (or the same as long as a request), the other pages () Gets setAttribute method getAttribute property.

What JSTL that? What are the advantages?

JSTL (JSP Standard Tag Library, JSP Standard Tag Library) is an open-source Java tag library official, mainly by four standard tag libraries (core, format, xml, sql) components. Advantages are:

  1. Can simplify Java Web development, JSTL has been providing a variety of general-purpose label usually required to develop, so developers do not need to write basic custom label.

  2. JSTL can be avoided by using Java script to control the JSP page, in the actual business development, usually disables the output Java script on the JSP page.

How to avoid JSP pages automatically generated session object? Why should I do?

       By default, when a browser makes a request to a JSP page, if the session has not been established, the Web server will automatically create a session object for the request, but the session is resource consuming, if not necessary to maintain and use session , should not create a session, such as some just do products, company profile page, there is no need to use the session to save the information. Can be used in JSP page directive settings to avoid JSP pages are automatically created for each session request. Example code is as follows: <% @ page session = " false"%>

How to prevent duplicate submission form?

Use session tracking can be achieved:

  1. Generate a random value when the form page (such regist.jsp), save it in the session, and to save it as a value of the hidden form field.

  2. When the form processing request, acquires the value of the session value and a hidden field, comparing the two are the same, if not to repeat the same description, a request to save the value of the session by the deleted; if it is not repeatedly submit the same, can not be .

session and application of difference?

session on behalf of a user session, application represents the Web application itself. Specifically, they are the following differences:

  1. Different scope of both:

    session is a session-level user, application is a web application level. So application is a global scope. session corresponds to a user in a single session, single user session within the same visit to ask multiple pages to share the same session. The entire Web application to all users, all sessions share the same application, as long as the Web application does not restart, the data in the application has been effective.

  2. Different life cycle.

    session: the user is first created when accessing the website, the user logs off, leave the site or close your browser demise.

    application: starting the web server to create, destroy shut down the web server.

Talk about automatic login mechanism function.

It is automatically logged by Cookie to achieve.

  1. When the user's first login, the program needs to be logged into Session addition, the login information will be stored in Cookie, Cookie stored on the user's computer.

  2. When a user visits the site again, the Cookie information read directly on the user's computer, if Cookie existing login information, the login information will be written in the Cookie Session, which implements automatic login.

EL expressions that? Why use EL expression?

EL stands for Expression Language (expression language), which main features include:

  1. Reading data from the four fields and objects displayed.

  2. And displaying data read request parameters.

  3. Cookie read and display

  4. Support rich Operators

 

JSP 2.0 EL is introduced functions, can be easily accessed by EL, display data. Traditional JSP script, JSP expression data for displaying the trouble, there is a disadvantage that they tend to:

  •  Need to embed JSP scripts JSP page
  • Often requires judgment
  • Sometimes the need for type conversion

 

The role of cookie and session, the difference, the scope of application?

  1. cookie data stored on the customer's computer, session data is stored on the server.

  2. cookie is not safe, people can read, modify and even cookie on the client computer, or even cookie can be deceiving, and therefore not suitable for cookie-related data storage security, better data security requirements should be saved to the server using the session .

  3. session will be kept within a certain time on the server, but will take up memory resources, when excessive user access, will increase the load on the server, taking into account to reduce the pressure on the server, important data can be saved in a cookie lasting .

  4. Single cookie saved data can not exceed 4k, many browsers are limited to multi-site save 20 cookie.

Guess you like

Origin www.cnblogs.com/bzbz/p/11994564.html