• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Servlet concepts doubts

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 93
Python Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Grow your own food... or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic