| 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: 12268
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
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 ?
|
 |
 |
|
|
subject: show any www
|
|
|