• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet filter being invoked twice per request by Container.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
enterrement de vie de garзon idйes
Cani
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
reply
    Bookmark Topic Watch Topic
  • New Topic