• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Two "Post"s on the same html page valid?

 
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets newbie alert.

I am trying to invoke 2 different servlets from my HTML page based on the Submit button pressed. My html page -

<form method="POST" action="DownloadJar.do">Download at your own risk!
<br>
<center><input type="SUBMIT"></center>


<form method="POST" action="GetInitParams.do">Support Information just in case!
<br><br>
<center><input type="SUBMIT"></center>


And my web.xml -
<servlet>
<servlet-name>Download My Jar Now</servlet-name>
<servlet-class>com.examples.web.downloadJar</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Download My Jar Now</servlet-name>
<url-pattern>/DownloadJar.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Those people have asked for it this time</servlet-name>
<servlet-class>com.examples.web.getInitParams</servlet-class>
<init-param>
<param-name>adminEmail</param-name>
<param-value>[email protected]</param-value>
<param-name>mainEmail</param-name>
<param-value>[email protected]</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Those people have asked for it this time</servlet-name>
<url-pattern>/GetInitParams.do</url-pattern>
</servlet-mapping>

Pressing either Submit button always invokes the first servlet. Are we allowed to have 2 Post requests on the same html page at all? Or is something else the matter.

Thanks!
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can, but you need to have a single form and use each button to change the form.action to the right value before submitting. Then everything should be OK.

Dave
 
Jenna Thomas
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your answer Dave, but I cant find any sample code for that, how do I go about invoking 2 different servlets from the same form? Skeleton code would do. Thanks again!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well firstly the simple answer may be to create valid HTML - you haven't closed your tags. Therefore it could be as simple as closing the first form:


[ July 23, 2006: Message edited by: David O'Meara ]
 
Jenna Thomas
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David, it worked!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another approach, worth looking in to, is the "Front Controller" or "Command" pattern.

In your HTML form:


In your controller servelet:


By loading your actions into a Map, you can avoid the long if/else statement.
I have a working example of this on my site: http://simple.souther.us
See: SimpleCommand
[ July 23, 2006: Message edited by: Ben Souther ]
 
Sheriff
Posts: 67752
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
The problem with the code in your first point is that you have the forms embedded in each other (no </form> for the first form). That cannot be.

But you can have as many indepenendent forms with disparate actions on your page as you would like.
 
Jenna Thomas
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear.

Will check this approach Ben. Thanks for your time!
 
Well THAT's new! Comfort me, reliable tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic