File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet filter being invoked twice per request by Container.

 
Sivapraveen Chandana
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
tolu tolu
Greenhorn
Posts: 2
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing any client-side validation in JavaScript? I've seen this happen sometimes due to faulty form submission logic.
 
Sivapraveen Chandana
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic