• 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

One servlet One JSP 2 forms

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One JSP, which contains two forms.

   

 The goal is  to send data from this forms to one servlet, which inserts its to database.  
From one form data values must be inserted to one table-database,  from second form - to second table-database, accordingly.




   But when I try to send data from one of this forms (for example "newsModalDialog"), joint table is created. This table contains fields from two tables. And this new table is empty.

  Thus, values are not inserted to database, through servlet.

  I hope, I created my topic in a proper branch of forum.
 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How have you mapped the forms? Are you using two entities?
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:How have you mapped the forms? Are you using two entities?



   On the level of Servlet-Hibernate interaction:
   Two models:




   Save







  Mapping in hibernate.cfg.xml

 
  Also code, which creates SessionFactory exemplar
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
   Excuse, a mistace in previos post:
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this stackoverflow post, it might help you
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Have a look at this stackoverflow post, it might help you



  Thanks. And in this post the ENTITY FRAMEWORK is considered?
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is...
 
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you don't have two forms in that HTML code. The second half is a form; the first half would be a form except that its opening tag is



Perhaps if that were a "form" opening tag your code would work the way you liked?

(You realize that you can only submit from one form at a time, right?)
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But you don't have two forms in that HTML code. The second half is a form; the first half would be a form except that its opening tag is



Perhaps if that were a "form" opening tag your code would work the way you liked?

(You realize that you can only submit from one form at a time, right?)



Paul Clapham, thank you, it was really stupid mistake from my side!
 Of course "form" - not "input" in this tag!
After I corrected it, the code worked properly.
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  I'm sorry, but not all problems have been solved.
  When I try to send data, been inputed in one of forms, to servlet,   values inserted to table successfully - but.. the are duplicated.
 
  When I use only one form in jsp for this purpose the problem is absent.





 
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
You never really adequately explained why you are using two forms in the first place.

That is highly irregular. And when something is highly irregular, its a good bet that it's not the best approach.

So why the two forms?
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You never really adequately explained why you are using two forms in the first place.

That is highly irregular. And when something is highly irregular, its a good bet that it's not the best approach.

So why the two forms?



  I use two forms, because its a structure of web-page. Page consists of 2 parts. Each part is used for sending different kinds of data to different tables in DB.
  For example, one part - for news, other - for push-messages.
  Or any other way to realise this structure is possible?
 
Bear Bibeault
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

Andrey Dmitriev wrote:
  I use two forms, because its a structure of web-page. Page consists of 2 parts.


This still doesn't explain the two forms. The style of the page isn't usually relevant. Even if it has two sections, why cannot a single form encompass the two sections?

Each part is used for sending different kinds of data to different tables in DB.


This in no way requires there to be two forms. What you do with the data once it gets to the servlet and is passed down to the data layer has nothing at all to do with the layout of the page.

As has been pointed out: one form per request. If the data from both sections of the page need to be submitted at the same time to a single request, there should be only one form.

Is there something other than the above that is preventing you from creating a single form?
 
Bear Bibeault
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
Answering my own question after looking more closely to the code.

Ah, you have the forms in separate modals. Can you explain how they interact? How do users use the two modals? At what point is the data actually submitted?

It seems really weird to have two modals, if the data from both gets submitted at the same time. Is that what you are trying to do?
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  Oh, I did not attached importance on one thing. Modal windows must be different.
  Further I m going to add in second modal 3-d filed - for inputting graphical data aims.

  Modals have an identical structure now, as I no time to modify them.
 
 
Paul Clapham
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are those forms submitted when the user presses the button labelled "Сохранить", or is there some JavaScript code elsewhere which submits them?
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Are those forms submitted when the user presses the button labelled "Сохранить", or is there some JavaScript code elsewhere which submits them?



   Yes, forms are submitted when the user presses the button labelled "Сохранить"
 
Andrey Dmitriev
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Are those forms submitted when the user presses the button labelled "Сохранить", or is there some JavaScript code elsewhere which submits them?



   Yes, forms are submitted when the user presses the button labelled "Сохранить"

   Sorry for delay with reply -
 
reply
    Bookmark Topic Watch Topic
  • New Topic