This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes POST method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "POST method" Watch "POST method" New topic
Author

POST method

Raj Kumar
Ranch Hand

Joined: Sep 19, 2005
Posts: 65
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

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
Raj Kumar
Ranch Hand

Joined: Sep 19, 2005
Posts: 65
thanks rahul for the reply, but is not there a way as simple as "GET" method.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I do not think.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Raj Kumar
Ranch Hand

Joined: Sep 19, 2005
Posts: 65
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

Joined: Feb 07, 2004
Posts: 472

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.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Sep 19, 2005
Posts: 65
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

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Sep 19, 2005
Posts: 65
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

Joined: Sep 19, 2005
Posts: 65
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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: POST method
 
Similar Threads
call a html/jsp page from an applet and pass parameters in post method
Retrieving a drop-down list value.
Send file to applet from PHP
refresh in post method
Error 405