aspose file tools*
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
Author

show any www

marko stone
Greenhorn

Joined: Oct 16, 2002
Posts: 23
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Oct 16, 2002
Posts: 23
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 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: show any www