Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POST method

 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have three web applications deployed on the same Tomcat named
WebappParent, WebappClild1, WebappChild2.

Here WebappParent will get the username & password validates that and based upon the previlege it will call a particular servlet in WebappChild1 (or) WebappChild2 using URLConnection and "POST" method

But here i want to know how to pass the request object which i had received from the browser to WebappParent and from there to either of the child application.

I tried this using "GET" method and passing parameters along with the URL and it worked perfectly.

Thanks in advance
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought this would not be a clean approach , but I do not see any other solution to this.

You can create a web application common repository and put that in shared/lib folder so that it can be shared across web application.
You can have the respository as singleton and should work like map interface(key:value).Now store the object in the respository in one application and send the key of that to the other application.
 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks rahul for the reply, but is not there a way as simple as "GET" method.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not think.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request, session, and context objects are bound to the webapplication in which they were created.
Why did you break your application in to multiple webapps if the different components need to interact with one another?
 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben Souther, What you asked is correct (i.e why you break webapplication??)
i know how to achive that with a single application but that's not my requirement.

What i think was if we have a way to request for a particular resource in a web application using URLConnection then there should be a way to pass request parameters & attributes too.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
POST isn't more complex. When you opened URL connection just obtain output stream and write parameter pairs '&' separated. You may need to URL encode them though. If you need to convert GET to POST you can just write query string directly.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by D Rog:
POST isn't more complex. When you opened URL connection just obtain output stream and write parameter pairs '&' separated. You may need to URL encode them though. If you need to convert GET to POST you can just write query string directly.


Raj Kumar is talking about passing object , rather the request object.
 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i should be much specific,

From the browser to WebappParent i received two values username & password as a "POST" method which after validation i just need to pass over to either WebappChild1 (or) WebappChild2.

With Pass over means the WebappChild which receives the call for request should do the processing as if it had received that from a browser (i.e. it should use request.getParameter("username")) to get the values.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While making the request to the second web application , append the parameters as key value pairs seperated by ampersand.At the other end you can well use request.getParameter("key") for getting back the values.

remember URL?key=value&key1=value1
 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Rahul that's what i'am doing now but what happens is some time it throws

exception caughtjava.io.IOException: Server returned HTTP response code: 505

even after using URLEncoder i'am facing this problem ...
 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rahul & others, i had fixed the problem the 505 error is because i had not encoded the URL once when i did that the problem is solved.

Thanks a lot for all you time...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic