"Holmes III, William S" wrote:
> Hi,
>
> Is it possible to have an action class
> - construct a new HttpServletRequest
> - send it to another site (possibly external)
> - process the resulting HttpServletResponce (parsing it and storing values
> into a bean)
> - then load attributes onto it's own HttpServletResponce to forward to a
> JSP
>
This is quite feasible. The secret is to have your action class use the
java.net.URLConnection to establish the connection to the possibly external site,
submit the request, and then read back the response. With the response, you can do
whatever you want -- it works the most easily when the response is an XML document
that you can parse, or a serialized Java object that you can deserialize and use,
or something like that.
There is example code to do this kind of thing in the "Networking Trail" of the
Java Language Tutorial, at <http://java.sun.com/docs/books/tutorial>.
If your request to the external server needs to set HTTP headers or other things
like that, you will want to slightly modify the example code in the tutorials:
* Ensure that you're using an "http:" URL to establish the connection.
* Follow the example down to the point of getting a URLConnection.
* Cast this connection object to an HttpURLConnection.
* Now you can do things like set the request method (for example, if
you need to do a POST instead of the default GET) or other HTTP
specific stuff.
>
> It sounds like a lot of overhead, but does anyone have any suggestions?
>
I think you'll see this type of architecture used more and more for B2B type
integration, especially when XML documents are used in the request and response to
send stuff back and forth.
>
> Thanks,
> Bill
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets