aspose file tools*
The moose likes Servlets and the fly likes When the jsp contacts the servlet for the first time in a session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "When the jsp contacts the servlet for the first time in a session " Watch "When the jsp contacts the servlet for the first time in a session " New topic
Author

When the jsp contacts the servlet for the first time in a session

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi

I am having a jsp page which sends a request to the servlet.

(In a session the jsp page contacts this servlet many times )

Is there any way so that to know that this particular request is the first request from the jsp .

Thank you


Save India From Corruption - Anna Hazare.
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

there are a lot of choices to do it . for example while forwarding use a parameter which can tell the servlet that the request is from the jsp.
based on the parameter you can create a counter.

avi sinha>


SCJP 5.0 SCWCD 5.0
Shakeel Shaik
Greenhorn

Joined: Jan 28, 2009
Posts: 5
You can try this approach

First write a listener that implements an HttpSessionListener
Implement the methods sessionCreated and sessionDestroyed, somewhat like this.


In jsp -> <% increment counter %>

In your servlet -> //check counter

hope this helps.
give it a try and let us know how it went.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

First of all . Thank all for you for help .

shaks ss what you said is a complex approach . I would prefer what sinha has mentioned .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

"shaks ss", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: When the jsp contacts the servlet for the first time in a session