wood burning stoves
The moose likes Servlets and the fly likes show any www Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "show any www" Watch "show any www" New topic

show any www

marko stone

Joined: Oct 16, 2002
Posts: 23
i have form for input url and i have servlet what show this web resource.i do it like this
have i can get web resource another, easy way ?

String sURL=req.getParameter("urladdr");
PrintWriter out=res.getWriter();
URL www=new URL(sURL);
URLConnection urlconn=www.openConnection();
InputStream is = urlconn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
if(in != null)
String line = "";
while((line=in.readLine()) != null)
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
You are close, but what you have does a lot of String conversions which are slow and only work with character resources.
You need to use a plain BufferedInputStream instead of a reader and use res.getOutputStream instead of getWriter. Then read and write byte[]s until the input stream is exhausted. That will
be faster and could serve binary data as well as character data.
marko stone

Joined: Oct 16, 2002
Posts: 23
i got another way
i use sendRedirect method
and have another problem now
i don't know how i can send parameters
(without session) from one servlet to another
trying use RequestDispatcher but not work
any solves ?
I agree. Here's the link: http://aspose.com/file-tools
subject: show any www
It's not a secret anymore!