jap proxy not work with images

Discussion in 'Java' started by pcanoe, Jun 20, 2011.

  1. pcanoe

    pcanoe New Member

    Joined:
    Jun 20, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello all.

    I have a problem.
    This is a proxy in jsp. It takes an url change it and recall it. It works with html file but not images. How can I make it work for images.

    Thank for all
    Cheers.

    Code:
     
    [COLOR=#bf5f3f][FONT=Courier New]<%@[/FONT][/COLOR][COLOR=#3f7f7f][FONT=Courier New]page[/FONT][/COLOR][FONT=Courier New] [COLOR=#7f007f]session[/COLOR][COLOR=black]=[/COLOR][I][COLOR=#2a00ff]"false"[/COLOR][/I][COLOR=#bf5f3f]%>[/COLOR][/FONT]
    [COLOR=#bf5f3f][FONT=Courier New]<%@[/FONT][/COLOR][COLOR=#3f7f7f][FONT=Courier New]page[/FONT][/COLOR][FONT=Courier New] [COLOR=#7f007f]import[/COLOR][COLOR=black]=[/COLOR][I][COLOR=#2a00ff]"java.net.*,java.io.*"[/COLOR][/I] [COLOR=#bf5f3f]%>[/COLOR][/FONT]
    [COLOR=#bf5f3f][FONT=Courier New]<%[/FONT][/COLOR]
    [B][COLOR=#7f0055][FONT=Courier New]try[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] {[/FONT][/COLOR]
    [B][COLOR=#7f0055][FONT=Courier New]if[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] (request.getParameter([/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"img"[/FONT][/COLOR][COLOR=black][FONT=Courier New]) != [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]null[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New]) {[/FONT][/COLOR]
     
     
     
    [COLOR=black][FONT=Courier New]           String strImage = request.getParameter([/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"img"[/FONT][/COLOR][COLOR=black][FONT=Courier New]); [/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           String strURL = [/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"a link in http"[/FONT][/COLOR][COLOR=black][FONT=Courier New]; [/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]           URL urlRequest = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]new[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] URL(strURL);[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           HttpURLConnection httpConnection = (HttpURLConnection)urlRequest.openConnection();[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]           httpConnection.setDoOutput([/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]true[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New]);[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           httpConnection.setRequestMethod(request.getMethod());[/FONT][/COLOR]
    [B][COLOR=#7f0055][FONT=Courier New]int[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] clength = request.getContentLength();[/FONT][/COLOR]
    [B][COLOR=#7f0055][FONT=Courier New]if[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New](clength > 0) {[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]                 httpConnection.setDoInput([/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]true[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New]);[/FONT][/COLOR]
    [B][COLOR=#7f0055][FONT=Courier New]byte[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New][] idata = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]new[/FONT][/COLOR][/B][B][COLOR=#7f0055][FONT=Courier New]byte[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New][clength];[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]                 request.getInputStream().read(idata, 0, clength);[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]                 httpConnection.getOutputStream().write(idata, 0, clength);[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           }[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]           response.setContentType(httpConnection.getContentType());[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]           BufferedReader rd = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]new[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] BufferedReader([/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]new[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] InputStreamReader(httpConnection.getInputStream()));[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           String line;[/FONT][/COLOR]
    [B][COLOR=#7f0055][FONT=Courier New]while[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] ((line = rd.readLine()) != [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]null[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New]) {[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]                 out.println(line); [/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           }[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]           rd.close();[/FONT][/COLOR]
     
     
     
     
     
    [COLOR=black][FONT=Courier New]     }[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]}[/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]catch[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New](Exception e) {[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]     response.setStatus(500);[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]}[/FONT][/COLOR]
    [COLOR=#bf5f3f][FONT=Courier New]%>[/FONT][/COLOR]
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice