• 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

Struts action not returning page on first click of button

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a couple of Struts forms representing poll questions. When the user chooses an option and submits, the vote is supposed to be processed, and the original page is updated to show the results rather than the original form. I am having to click twice to get the results to be shown. Below is the relevant code. Can anyone help me? Let me know if you need to see any other files.

Here is the JSP with the forms:


Here is one of the DAO classes. Both update the database correctly after each click. I'm just having to click twice, and I only want one click.


Here is my struts.xml:
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its hard to say what the problem is without the action code. Also you are setting HTTP Cookies in a DAO class?? This is a very bad design. Also each time the tallyVote method is called, hibernate is configured and session factory is built. Hibernate configuration should happen only once and then you can store the SessionFactory object in your DAO class (actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes). Again a bad design...
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Its hard to say what the problem is without the action code.



Here is the action code.


Ankit Garg wrote:Also you are setting HTTP Cookies in a DAO class?? This is a very bad design.



Why is it a bad design? Please suggest something better.

Ankit Garg wrote:so each time the tallyVote method is called, hibernate is configured and session factory is built. Hibernate configuration should happen only once and then you can store the SessionFactory object in your DAO class



I'm not entirely sure what you mean here. Please explain

Ankit Garg wrote:(actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes). Again a bad design...



Again, please elaborate why this is a bad design and what would be better.
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Also you are setting HTTP Cookies in a DAO class?? This is a very bad design.



I've put the cookies in the action class in the presumption that's better. I would still like an explanation as to why the cookies should not be in the DAO class.

Ankit Garg wrote:Also each time the tallyVote method is called, hibernate is configured and session factory is built. Hibernate configuration should happen only once and then you can store the SessionFactory object in your DAO class (actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes). Again a bad design...



Please explain why what I did is bad and what is better. I am still having the same problem.
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:(actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes)



So where do I store this class in my file system? When would it be called? How would it be called? Google searches aren't telling me this.
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:(actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes)



Never mind. I'll look elsewhere.
 
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic