aspose file tools*
The moose likes Servlets and the fly likes Servlet concepts doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet concepts doubts" Watch "Servlet concepts doubts" New topic
Author

Servlet concepts doubts

p hasini
Ranch Hand

Joined: Oct 24, 2009
Posts: 92

1. If we set setMaxInactiveInterval(int interval) to high value,does it mean the user's information will be maintained , after a user exits a browser and reopens the browser again.

2. We can create a Servlet in 2 ways.By extending GenericServlet or by extendiing HttpServlet.
Since GenericServlet and HttpServlet implement Servlet interface , can we write a servlet as



3. To create a session, we use


What is the difference between HttpServletReuqest.getSession(true) and HttpServletRequest.getSession(false)

4. How do we get a ServletConfig object.Are the following ways correct:


5. How do we get a ServletContext object.Can we use both these ways:

Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 88


3. For getSession(true), it will check whether there is a session already existing for the user. If a session is existing, it will return that session object, otherwise it will create a new one and returns it.

And for getSession(false), this will check whether a session exists or not. If yes, then it returns that session object, or else it will return null.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
1. If we set setMaxInactiveInterval(int interval) to high value,does it mean the user's information will be maintained , after a user exits a browser and reopens the browser again.


A session is only good for a single browser session just like the name implies. Note that the only user information in a session is what the programmer puts there, nothing is put there automatically.

For clearing your doubts about servlets, read the API - for example javax.servlet.http.HttpSession for the behavior of sessions.

Bill
Rahul Nair
Ranch Hand

Joined: Dec 01, 2007
Posts: 138
Hello,

Just to clear my doubt, How many ways we can create a session in Servlet ? Is there any other way except request.getSession() call ?

Thanks,

Rahul
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
As to #2, yes, you can write a servlet that way. But you'd have to duplicate everything GenericServlet and HttpServlet do, and in particular you'd need to implement the "service" method and its handling of the various HTTP methods.


Ping & DNS - my free Android networking tools app
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You can create a session in a servlet by calling getSession() or the overloaded method that takes a boolean, with a value of 'true' on the request object.

BTW, This information is readily available in the API or in the FAQ here.

Rahul Nair wrote:Hello,

Just to clear my doubt, How many ways we can create a session in Servlet ? Is there any other way except request.getSession() call ?

Thanks,

Rahul


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet concepts doubts