aspose file tools*
The moose likes Servlets and the fly likes Servlet being Invoked Twice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet being Invoked Twice?" Watch "Servlet being Invoked Twice?" New topic
Author

Servlet being Invoked Twice?

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
I have a pretty simple web application that I'm mocking up and I've run into something very peculiar.

The user comes to a certain page in which they can search the system for files. The page consists of two frames - the frame on the left contains controls for the user to enter their search criteria and a button to press to initiate the search. The frame on the right is empty, initially, but I'd like to populate it with the results of the search.

To this end, I've made my "control" (the frame on the left) page like this:



It's really pretty basic. The user can enter their search criteria and pressing the "Search" button causes the method submitForm() to be invoked. This method really only does two things. First, it pops up an alert to let me know it got there. Second, it changes the location of the other frame - redirecting it to a servlet so that it gets the result of the search.

I know that this method is only being invoked one time because I only get one pop-up box.

However, in the servlet that is called, I have a println statement so that I can be sure it got there - this statement executes two times.

Anyone have any idea why the doGet method is bring invoked twice when I set the location as I have above?

Thanks,
Corey


SCJP Tipline, etc.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Okay, let me add a bit more to the story...

I added a little more functionality to the web app. When the user performs a search, I first check to see if the user is logged in to the application (to prevent people trying to bypass the login page or a session that has timed out). If the user isn't logged in, I redirect them to another page. If they are logged in, I go ahead and perform the search. The code looks roughly like this:



The odd thing here is that, if the user is not logged in and I redirect them to the "session timed out" page, the doGet() method only executed once, as I'd expect. If, however, the user is logged in and I go ahead and return a file, it actually execued the doGet() method a second time.

I'm confused.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
I can only guess that something in your html code which does submission twice as regular and as a result of on click handler. You can verify that looking in access log your web server.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet being Invoked Twice?