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

Two requests in one doPost method, can this happen? Please I need help

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please I need someone to clarify this point for me as I googled for long time and didn't find any satisfactory answer.

I have a client that sends requests to bank servlet that should process the xml file and send it back to the client. Then I need that client again to send another XML file to the same bank servlet where it will process it again and send it back to the client. Is that possible?

I mean can the servlet recieves two different requests in one doPost() method? if so, how it will be able to distinguish b/w them so it will respond appropriately!
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mouza Ali:
I mean can the servlet recieves two different requests in one doPost()



possible


Originally posted by Mouza Ali:
if so, how it will be able to distinguish b/w them so it will respond appropriately!



you can do it in many ways like, hiddenfield,querystring ..etc
 
Mouza Ali
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply,

You mean that I pass a string to the servlet, like for example "Request1" or "Request2" and check over there if it is == "Request1" go to some method; otherwise, go to the other one?

Is this effecient?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes. you need to check that which purpose your are sending the request to the servlet
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what seetharaman venkatasamy means by "possible", but with HTTP 1 request means 1 response. You can't somehow deal with two successive requests at the same time in the doPost method.

What is the problem you are trying to solve? Why would it be problematic to handle two successive requests?
 
Mouza Ali
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

I mean that the servlet can handle two types of requests. I don't mean two requests that are the same and at the same time. For example, The servlet can recieve a request that asks to do addition and another request that asks to do subtraction but not at the same time.

For more explanation, when the first request is sent to the servlet, the first part of teh doPost() will do the addition and send the result back to the client, then the client take the result,process it and send it back to the servlet to do the subtraction. Finally, the servlet send the result back again to the client.

Hope you got what I mean, so do you have any suggestions, or using a string query is the only solution?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see. In that case, don't use a query string; use a hidden input field in your HTML form.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
I'm not sure what seetharaman venkatasamy means by "possible", handle two



hi, i mean instead of using multiple servlet for different functionality ...still you can use one servlet.


something like, in servlet

 
Mouza Ali
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This will be done on the servlet side, but how to control this on the client side? I mean what to insert into the code to let the paramter be specified to be either for the first request or for the second request?

For more clarification, you said that in the servlet side, I should use the getParamter method, but how to set it in the first place on the client side?
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You set it up as "Request1" by default, then during first elaboration you let your servlet set it as "Request2" and set it back in the form.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mouza Ali:
For more clarification, you said that in the servlet side, I should use the getParamter method, but how to set it in the first place on the client side?



As Ulf mentioned above use hidden field .



ofcourse you need to do some logic that prevent the null pointer exception in jsp
 
Mouza Ali
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,

I'm using neither jsp nor html form. I'm using the applet as client embadded as a tag in the html form. Is there anything similar but with Applet?

I'll appreciate your help!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, you never mentioned that the client was not a browser but an applet. With applets it would just be an extra HTTP parameter. How is the applet sending the data now? It must have some mechanism of assembling the various HTTP parameters already, no?
 
Mouza Ali
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Sorry. I thought I did, but it appears that I mentioned that in another post, oops!

The applet is using HTTP doPOST() method, when the client generates XML file, it will open a URL connection with the servlet, then it will open a stream to send the first XML file. Then, when the servlet receives it, it will process it again to send it back to the client by opening another stream.

When the client receives this XML file, it will generate another XML file to be sent again to the servlet, and so on..

Several xml files to be sent.

So can you give me more clarification about the paramters you mentioned? I googled for a very long time, and sometimes, I found that a service() method should be used, but not much explanation and documentation about that!

Can you help?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example of how to POST parameters in Java: http://www.exampledepot.com/egs/java.net/Post.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic