I want to build a simple JSP to act as a proxt to retrieve web page
(xml documents, actually) for an AJAX page (which cannot request
documents outside its own domain).
Please point me at some examples or give me a class name to start
with.
Thanks
Arne Vajhøj - 04 Mar 2007 01:21 GMT
> I want to build a simple JSP to act as a proxt to retrieve web page
> (xml documents, actually) for an AJAX page (which cannot request
> documents outside its own domain).
>
> Please point me at some examples or give me a class name to start
> with.
Use a servlet instead of a JSP page.
Several JSP AJAX toolkits exist that comes with an
easy to extend servlet.
Arne
richardchaven - 04 Mar 2007 22:56 GMT
> Use a servlet instead of a JSP page.
I want to be able to deploy a minimum of files (ideally one) without
configuring anything. If I can use a jsp to get data from a different
page, that will be the simpliest.
I've seens a reference to a custom tag library that allows one to, for
instance, embed a quote from a different site in a JSP, so it seems
like this is theoretically possible.
Any ideas ?
Arne Vajhøj - 05 Mar 2007 03:56 GMT
>> Use a servlet instead of a JSP page.
>
[quoted text clipped - 7 lines]
>
> Any ideas ?
Try and take the body of servlet code below and copy
into a <% %> block in your JSP page.
But I warn you. You can easily get problems
with content type and blank lines when doing
what is servlet work in a JSP page.
Arne
================================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.*;
public class CopyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
try {
URL url = new URL("http://www.foobar.dk/");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.connect();
if(con.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = con.getInputStream();
byte[] b = new byte[1000];
int n;
while((n = is.read(b)) >= 0) {
String s = new String(b,0,n);
response.getOutputStream().println(s);
}
is.close();
}
con.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Daniel Pitts - 04 Mar 2007 18:49 GMT
On Mar 3, 4:39 pm, "richardchaven" <goo...@thistooshallpass.org>
wrote:
> I want to build a simple JSP to act as a proxt to retrieve web page
> (xml documents, actually) for an AJAX page (which cannot request
[quoted text clipped - 4 lines]
>
> Thanks
you would probably be better off getting a real proxy.
We use Resin for our webapps, and Apache as our webserver. Apache can
use ProxyPass to pass certain URLs to other sites.
Of course, there are plenty of other ways to do this :-).
Hope this helped,
Daniel.