大家好,我用jsp页面依次获取多个图片的时候有时候能刷出图片,有时候不能刷出图片。以下是我的获取图片的代码------------------------------img.jsp-------------------------------<%@ page contentType="image/jpeg" import="javax.imageio.stream.ImageOutputStreamImpl,java.io.*,java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*,com.sdw.wlcity.util.*,org.json.*,org.apache.commons.httpclient.*,org.apache.commons.httpclient.methods.*" %><%
response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    String url=request.getParameter("url");
     HttpClient ht;
ht = (HttpClient) request.getSession().getAttribute("sys_httpcilent");
if (ht == null) {
ht = new HttpClient();
request.getSession().setAttribute("sys_httpcilent", ht);
}
PostMethod post = new PostMethod(Constant.URL_GET_FILE);
try {
JSONObject jsonObj = new JSONObject();
jsonObj.put("file_url", url);
post.setRequestBody(jsonObj.toString());
ht.executeMethod(post);
} catch (Exception e) {
e.printStackTrace();
}
byte[] bytes =post.getResponseBody() ;
response.getOutputStream().write(bytes,0,bytes.length);
%>我通过在其他页面使用  <img src="img.jsp?url=<%=url%>"  alt="img" />  这种方式来引用以上代码。
环境:tomcat6, httpclient3.0   opera11报的异常不固定,一般都是协议方面的异常,一下我列举出几个异常:org.apache.commons.httpclient.ProtocolException: The server wirelesscity.icu.net.cn failed to respond with a valid HTTP response
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1846)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)java.io.IOException: chunked stream ended unexpectedly
at org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:251)
at org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:220)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:175)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:107)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
org.apache.commons.httpclient.ProtocolException: The server wirelesscity.icm.net.cn failed to respond with a valid HTTP response
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1846)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)从以上信息来看有可能是服务端的错误。但是用另外一个android上的产品访问服务端的接口就不会出现问题。哪位高手帮帮忙,看看问题在哪里

解决方案 »

  1.   

    The server wirelesscity.icm.net.cn failed to respond with a valid HTTP response
    看这意思貌似是无线传输出现的问题。
      

  2.   

    我用pc的opera浏览的时候就会出现问题。但是使用手机的浏览器浏览就基本上正常,后台偶尔也会报异常。但是不像用pc浏览器那么多。手机上的图片能正确显示出来。
    以下我再加个报的异常:I/O exception (java.net.SocketException) caught when processing request: Socket is closed
      

  3.   

    Socket is closed
    这个跟浏览器没关系,好像是网络中断了。
      

  4.   

    会不会是我循环调用导致的问题?
    我调用的代码中会有
    <%
    for (int i=0  ; i< length;i++){ 
    String url="一个新的图片地址"
    &>
    <img src="img.jsp?url=<%=url%>"  alt="img" /><%} %>类似这种在一个jsp中循环调用  会 导致这种问题吧?