aspose file tools*
The moose likes Servlets and the fly likes Servlet filter being invoked twice per request by Container. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet filter being invoked twice per request by Container." Watch "Servlet filter being invoked twice per request by Container." New topic
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: 12821
    
    5
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
Abdul Rahman
Ranch Hand

Joined: Jul 04, 2008
Posts: 63
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: 61588
    
  67

Are you doing any client-side validation in JavaScript? I've seen this happen sometimes due to faulty form submission logic.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet filter being invoked twice per request by Container.