This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet concepts doubts

 
p hasini
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 91
Android AngularJS Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic