| Author |
Servlet filter being invoked twice per request by Container.
|
Sivapraveen Chandana
Greenhorn
Joined: Jan 01, 2008
Posts: 16
|
|
Hi,
I am facing a peculiar problem in my web application. Whenever I click on a button in a jsp, the web container is invoking the servlet filter twice. The entire flow is thus, getting executed twice. The action to be performed is insert a row in a table in database.
Due to the above problem, each time I submit a form, instead of one entry, two entries are made in the database table.
Have you faced such a problem ?
Your advice/insight is appreciated.
Thanks in advance..
Praveen.
|
praveen
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
|
|
I think we would need to see the deployment descriptor (web.xml) that defines the servlet and filter before taking a guess.
Exactly what kind of request does this "button in a jsp" create?
[picky-mode]Your jsp creates an html page, therefore the button is not really "in a jsp"[/picky-mode]
Bill
|
Java Resources at www.wbrogden.com
|
 |
Abdul Rahman
Ranch Hand
Joined: Jul 04, 2008
Posts: 62
|
|
Hi Praveen,
The filter is used for both the incoming request and the outgoing response. Have you duplicated the code in the response part of the filter as well ?
Please do share us the part of the code concerned. This will help us to analyse better your problem.
|
Abdul
SCJP5, SCWCD5, [scwcd wall of fame]
|
 |
tolu tolu
Greenhorn
Joined: May 16, 2009
Posts: 2
|
|
enterrement de vie de garзon idйes
Cani
|
enterrement de vie de garзon idйes
Cani
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56178
|
|
|
Are you doing any client-side validation in JavaScript? I've seen this happen sometimes due to faulty form submission logic.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sivapraveen Chandana
Greenhorn
Joined: Jan 01, 2008
Posts: 16
|
|
Thanks to all for your inputs..
I found out the cause of this. In my jsp, I was using
<html:submit ...................../> earlier which was causing the problem.
I changed the above to
<html:button...................../> which resolved the problem.
On clicking the button, a javascript function is invoked.
Thanks again..
|
 |
Sivapraveen Chandana
Greenhorn
Joined: Jan 01, 2008
Posts: 16
|
|
Hi All,
To add to the previous reply, the mistake was that I was using <html:submit.../> which submits the form when the button is clicked. Additionally, I was using the onclick property to call a javascript function which contained the code
document.form.submit();
So, the request was being submitted twice.
Using <html:button.../> does not submit the form on clicking the button. Instead, we have to use document.form.submit(); to submit it.
Thanks..
|
 |
 |
|
|
subject: Servlet filter being invoked twice per request by Container.
|
|
|