• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

show any www

 
marko stone
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
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();
res.setContentType("text/html");
try
{
URL www=new URL(sURL);
URLConnection urlconn=www.openConnection();
urlconn.connect();
InputStream is = urlconn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
if(in != null)
{
String line = "";
while((line=in.readLine()) != null)
{
out.println(line);
System.out.println(line);
}
}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
 
marko stone
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic