• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to call multiple servlets from a single form?

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy fellow ranchers,
Is it possible to generate multiple requests from a single form which are passed to different servlets.
(i.e. The user hits submit and two different servlets receive requests?)
Any suggestions would be greatly appreciated.

------------------
Regards,
Travis M. Gibson, SCJP
Java Developer
www.travismgibson.com
[email protected]
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Uhmm, why??
What functional advantage would you get if this was a possibility?
As far as I understand, forms have one action. A form will submit one request. What you do with that request could have an infinite number of servlets.
 
Travis Gibson
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew,
We have a JSP form. Once the form is complete it is written to a database however we also want to kick off an additional servlet
which will send an e-mail to the person who entered the form.
Forwarding the request through the database update servlet to the e-mail servlet is not an option.

------------------
Regards,
Travis M. Gibson, SCJP
Java Developer
www.travismgibson.com
[email protected]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't we do using JavaScript? (If you prefer to use JavaScript ). May be we can have another form in the same page. Like FormA and FormB. FormA's "action" call EmailServlet and FormB's action will call DbUpdateServlet.
But when FormB's Submit is clicked, you write an onClick JavaScript function which will first submit
formA and then formB. You may have to have hidden fields in FormA which are needed for EmailServet to send email.
regds
maha anna
 
Travis Gibson
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maha,
I didn't even think of that but you are right. I can use an OnClick event.
You and you example have been an inspiration to me. I used your website a great deal while I was chasing my SCJP. Now that I am a Java Developer I still find your advice very valuable.

------------------
Regards,
Travis M. Gibson, SCJP
Java Developer
www.travismgibson.com
[email protected]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its not possible i suppose bcoz
for every submit of form, there is action defined in form defination and we can define only one action for one form.
correct me if i am wrong
sachin
 
Andrew Shafer
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think Maha is right, as usual.
But it seems like you are better off handling things on the server side.
In order to have the form make two request, you will need to do JavaScript to read the input from the visible form and send this as a seperate request in an onClick event.
Seems like a big pain in the behind, when you could handle all this with one request on the server side.
If you don't want to forward anything from the Dbase servlet (why not?) then maybe a controling servlet that can call both the db servlet and the email servlet.
Benefits= one request + pure java
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personal choice would be do all control,business logic AND form validation at server side and make the client as thin as possible.
The decision may also depend on the variety of audience. Whether you could control the users. For example some corporate web applications are used by only known audience( example : employees of a company) and they can be asked to turn on Javascript. But if it is going to reach wide audience, for example an e-commerce web appln, if you want to make this web application more successful, then better not to insist the user to use javascript.
I have talked to some companies who have ASP models say our clients will use only IE.X.X version wirh java and javascript enabled browser and still successful.

regds
maha anna
[This message has been edited by maha anna (edited April 26, 2001).]
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Travis wants to do is so tricky because he is using the wrong tool for the job. A HTTP servlet (or JSP, or ASP) is a component which receives HTTP client requests and generates a HTTP responses to those clients. Anything that is not part of a chain which starts with the HTTP request and ends with the HTTP response should not be a servlet, JSP, ASP or whatever.
The database update is best done in a JavaBean, class, custom tag, or EJB. If you want the update to happen asynchronously, i.e. move it out of the request->response chain, consider using JMS. Or in its most basic form, kick off a separate thread for the purpose.
The e-mail facility does not want to be a servlet at all. Again, a JavaBean, class, tag, or (session) EJB could all be appropriate. And here too, if you want it to happen asynchronously, use JMS or a thread. A slightly more sophisticated alternative to kicking off a Thread for every e-mail would be to have an application-bound Java object which receives sendEmail() requests and has its own permanently running Thread in which it sends them off to the mail server.
- Peter

[This message has been edited by Peter den Haan (edited April 27, 2001).]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you could possibly do is call a single servlet which has include statements to call different servlets. This will probably mimic the call to multiple servlets.
However, I doubt there is a way (even using javascript) that you can call multiple servlets with a single click. Even if you use javascript, once a servlet is called, it loses control over the client and the control passes to the server.
You could probably use client pull type code if you want to call multiple servlets after intervals, but frankly, how it is implemented is something I have not tried as yet.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sure its easy to submit a single form to multiple sources but once you submit which servlet do u want to receive the next page from?
let me know and i can be more specific abt the code that can help u do that ...but a more general example is by using javascript have a function that gets called when the form is submitted onSubmit="callSubmit(this.form,'http://mywebserver ort/servlets/myServlet1')")
function callSubmit(form, servletSrc)
{
form.target = "_new"; /* this will display the input from the servlet in a new page while the old page is still open in the background */
form.action = servletSrc;
form.submit();
}
i hope u get the picture ??
-manav
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic