This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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 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>