下面程序无法显示图片,其实程序很简单,就是通过JSP给变量赋值,但是就是不显示图片,请指点<%@ page language="java" pageEncoding="GBK"%><%
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'one.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="contentType" content="html/text;charset=GBK">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body bgcolor=cyan>
    <% 
     String s="\"D:/wwwjsp/picture/hx.jpg\"";
     %>
     <img src=s></img> 
  </body>
</html>
如果我把<img src=s></img>改为<img src="D:/wwwjsp/picture/hx.jpg"></img>图片是能显示的。

解决方案 »

  1.   

    这样来:
     <img src="<%=request.getContextPath()%>/图片文件所在的文件夹的名称,若没有则省略/图片文件名"></img>
      

  2.   

    String s="\"D:/wwwjsp/picture/hx.jpg\""; 
    你的String类型s中的"/"需要转义的
      

  3.   

    String s = \"D:\\\\wwwjsp\\\\picture\\\\hx.jpg\\\\";
    这样试试
      

  4.   

    错有两处:
    一是路径书写不对;
    二是没有输出jsp的值
     <%
       String s ="C:/Documents and Settings/Administrator/My Documents/eb675e0fe214ca366159f351.jpg.gif";
       //前面无需加"\"
     %>
    <img src="<%=s %>" />
    //此处要写输出s,不然html并不能识别s变量
    以实验过,完全能够通过
      

  5.   

    补充:上面重要的2句改为下面,则又无法显示,麻烦解答
        <% 
         String s="hx.jpg";
         %>
         <img src="D:/wwwjsp/picture/"+<%=s %>></img>
      

  6.   

      <img src="D:/wwwjsp/picture/ <%=s %>"> </img>改成这样就可以了