Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple form with one action

 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
My jsp page contain 2 formsand name is form1 form2 . every form action is one action.jsp and method is post. how to read forms data.
see code
<form name="form1" method="post" action="action.jsp">
<input type="text" name="field1">
<input type="submit" name="Submit" value="Submit">
</form>
<form name="form2" method="post" action="action.jsp">
<input type="text" name="field1">
<input type="submit" name="Submit" value="Submit">
</form>
 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use POST the entire form object will be passed. So I think you can use the <formname>.<fieldname> to read the data. Correct me guys, If I am wrong.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use request.getParameter(), reguest.getParameterValues() to read your form data.

Bosun
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might add that if you click submit on form2, there is no way you can retrieve form1's data. And you can't nest forms either.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic