INTERVIEW QUESTIONS
J2EE
JSP
DETAILS
Question: How do you prevent the Creation of a Session in a JSP Page and why? What is the difference between include directive & jsp:include action?
Answer: By default, a JSP page will automatically create a session for the request if one does not exist. However, sessions consume resources and if it is not necessary to maintain a session, one should not be created. For example, a marketing campaign may suggest the reader visit a web page for more information. If it is anticipated that a lot of traffic will hit that page, you may want to optimize the load on the machine by not creating useless sessions.
|
Question:
How do you prevent the Creation of a Session in a JSP Page and why? What is the difference between include directive & jsp:include action?
Answer:
By default, a JSP page will automatically create a session for the request if one does not exist. However, sessions consume resources and if it is not necessary to maintain a session, one should not be created. For example, a marketing campaign may suggest the reader visit a web page for more information. If it is anticipated that a lot of traffic will hit that page, you may want to optimize the load on the machine by not creating useless sessions. Source: CoolInterview.com
Disabling the session in some pages will improve the performance of your JSP container. Every time a JSP is requested, JSP creates an HttpSession object to maintain state for each unique client. The session data is accessible in the JSP as the implicit session object. In JSPs, sessions are enabled by default. Session object uses the server resources. Each session object uses up a small amount of system resources as it is stored on the server side. This also increases the traffic as the session ID is sent from server to client. Client also sends the same session ID along with each request. If some of the JSP pages on your web site are getting thousands of hits from internet browser and there is not need to identify the user, so its better to disable the session in that JSP page. You can tell the container to disable session in the JSP file by setting the session attribute to false. Set the session attribute of the page directive to false, as shown in the following example: <%@ page session="false" %>. The <jsp:include> element allows you to include either a static or dynamic file in a JSP file.The <%@ include %> directive inserts a file of text or code in a JSP file at translation time, when the JSP file is compiled. When you use the <%@ include %> directive, the include process is static. A static include means that the text of the included file is added to the JSP file Source: CoolInterview.com
Answered by: Rohit | Date: 11/12/2009
| Contact Rohit
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|