This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

One servlet One JSP 2 forms  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you mapped the forms? Are you using two entities?
 
Andrey Dmitriev
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   Excuse, a mistace in previos post:
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this stackoverflow post, it might help you
 
Andrey Dmitriev
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is...
 
Sheriff
Posts: 24373
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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: 66
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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: 66
  • Mark post as helpful
  • send pies
  • 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.





 
Marshal
Posts: 67256
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 66
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 67256
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 67256
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 66
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 24373
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 66
  • Mark post as helpful
  • send pies
  • 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: 66
  • Mark post as helpful
  • send pies
  • 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 -
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!