Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSF
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JSF
Sending a request and a response From a Managed Bean
Ayaan Dar
Greenhorn
Posts: 10
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have a Managed Bean that needs to send a request to a
Servlet
deployed on a Separate Server and read the response from it . How can i do this?
Kind Regards.
Maroun Baydoun
Greenhorn
Posts: 4
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am not sure you can invoke a remote server the way you're intending. A workaround would be to use a URLConnection that will send a request to the servlet and will enable you to get some form of feedback
For example:
URL url= new URL("url of the servlet"); URLConnection yc = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) //Here you can read the servlet response and handle it appropriately in.close();
Ayaan Dar
Greenhorn
Posts: 10
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is exactly the way i did it. Here is the complete code for anyone who wants its
//I neaded to send params in the Query String. String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(imageString.toString(), "UTF-8"); URL url = new URL(PATH_TO_SERVER); URLConnection conn = url.openConnection(); conn.setDoOutput(true); wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); rd = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line; StringBuffer tempBuffer = new StringBuffer(); while ((line = rd.readLine()) != null) { tempBuffer.append(line).append("\n"); }
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Calling Osgi service from Servlet
Newbie question on resubmit of page not executing bean
managing Faces-config in jSF ...please explain.
Accessing JSF sesson bean from a servlet
JSTL to retrieve and pass request objects
More...