JSP enterprise interview questions (3)

Source: Internet
Author: User

JSP enterprise interview questions (3)

4-1. How can I achieve page Jump in several ways?

JSP: forward operation command is used to forward the current JSP page to another page. The basic syntax is "<JSP: Forward page =" test2.jsp "/>". When this function is used, the address in the browser's address bar will not change.

The most common method for response objects is the sendredirect () method. You can use this method to forward requests from the current client to other pages. The corresponding code format is: "response. sendredirect (" url address ");

4-2 What are the functions of the synchronized keyword?

In general, the synchronized keyword is added before the function. The function is that when a user executes this method, other users must wait until the user completes the operation.

4-3. What is the function of the out object? What is the difference between out. Print and document. Write?

The out object is a subclass of the javax. servlet. jsp. jspwriter class. It is used to send information back to the browser of the client. Among out objects, the most common methods are print () and println (). When using the print () or println () method, because the client is a browser, you can use some HTML tags when outputting data to the client, for example, "out. println ("

Out. Print is the JSP code and is interpreted and executed by the server.

Document. Write is a javascript code that is interpreted and executed by the client browser.

4-4. How do I obtain the IP address of the client?

The request object can be used to obtain information submitted by the customer, such as the JSP file directory, client address, and server port,

<Br> obtain the customer's IP Address:

<% String IP = request. getremoteaddr ();

Out. println (IP); %>

4-5. What are the characteristics of the Application object? What is the connection and difference with the session object?

All users of the site share an application object. When the Site Server is enabled, the application is created until the website is closed.

The Session object can be used to store the information of users logging on to the website. When a user redirects between pages, the variables stored in the session object will not be cleared.

Contact: data is stored on the server and can be retained for a period of time.

The difference is that each user has a session, but the application is common.

4-6. How does the program write a cookie set to the browser and read the cookie set from the browser.

Cookie objects are information stored in the browser after being generated by the Web server. Cookie objects can be used to save a small amount of information in the browser. Currently, mainstream browsers (Internet Explorer and Netscape Navigator) Support cookies.

Case name: Write cookie

Program name: 4-25.jsp

<% @ Page contenttype = "text/html; charset = GBK" %>

<%

String strname = "zhourunfa ";

Cookie c = new cookie ("name1", strname );

Response. addcookie (C );

%>

Case name: Read cookie

Program name: 4-26.jsp

<% @ Page contenttype = "text/html; charset = GBK" %>

<HTML> <body>

<%

Cookie Cookies [] = request. getcookies ();

For (INT I = 0; I <cookies. length; I ++ ){

If (Cookies [I]. getname (). Equals ("name1 "))

Out. Print (Cookies [I]. getvalue ());

}

%>

 

Related Article

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.