Servlet class creating multiple objects

Hi

I am using WSAD 5.0. My servlet is acting as a controller but when when i m invoking the servlet from 2 JSPs , server is creating 2 objects for that servlet because of which i m not able to get the values which was set by the first servlet object..

Can somebody tell me why the server is creating 2 objects for my servlet.

Alok

[356 byte] By [AlokMohantya] at [2007-11-26 18:32:17]
# 1
Aren't you makng to posts?MeTItus
Me_Titusa at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
m using service method in the servletMessage was edited by: AlokMohanty
AlokMohantya at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
"The init method is guaranteed to be called only once during the Servlet's lifecycle. It does not need to be thread-safe because the service method will not be called until the call to init returns."What I was asking before was wether you were making too posts or
Me_Titusa at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Thanks for ur reply.I m using post in my JSPs. The init method is called twice when i m invoking from 2 JSPs.Alok
AlokMohantya at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

No.. its is invoked only once.

If an instance of the servlet does not exist, the Web container

Loads the servlet class.

Creates an instance of the servlet class.

Initializes the servlet instance by calling the init method. Initialization is covered in Initializing a Servlet.

Invokes the service method, passing a request and response object. Service methods are discussed in the section Writing Service Methods.

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets4.html

MeTitus

Me_Titusa at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
service is called twice, init just one.MeTitus
Me_Titusa at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

The reason I am saying init method is called twice is because I ve written

init()

{

sop("I am called");

}

destroy()

{

sop("I am destryoyed");

}

when i invoked the servlet from 2 JSPs the 2 times "I am called" is showing and when I stopped the server, its showing "I am destroyed" 2 times.

This shows the init method called twice.

do we have any kind of configuration in the server which can create multiple servlet object.

AlokMohantya at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

hi

I found the problem. The way of invoking the servlet from 2 JSPs were different. In the first JSP i was using the URL-PATTERN of the servlet from web-cofig.xml and in the second JSP I was hitting the servlet by using the direct path i.e servlet/packege.MyServlet which is in the class folder.

I guess this is the reason thats why server could not able to identify whether servlet object is same as the previous one or not.

Thanks

Alok

AlokMohantya at 2007-7-9 6:06:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...