下面程序无法显示图片,其实程序很简单,就是通过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>图片是能显示的。
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>图片是能显示的。
解决方案 »
- 怎么在jsp页面中显示
- MyEclipse怎样运行applet程序?
- 请教高手,Digester可不可以赋值非节点中的数值?
- 请教JSP如何读取和写入sqlserver2000的text类型字段!急
- 100分!关于文件下载到客户端
- SimpleDateFormat方法需要用到哪些包或者方法啊?
- 通过hibernateTemplate.find().get(0)查询单个对象报错?
- 以代理方式上网,javamail连接邮件服务的有何不同吗?
- 关于中日英在JSP网页显示的问题
- 高分求教:如何在Win2000中将IIS5.0和Tomcat4.0进行结合????
- 过滤器出去死循环
- 写连接数据库的java文件时,编译是出错说是不兼容类型。
<img src="<%=request.getContextPath()%>/图片文件所在的文件夹的名称,若没有则省略/图片文件名"></img>
你的String类型s中的"/"需要转义的
这样试试
一是路径书写不对;
二是没有输出jsp的值
<%
String s ="C:/Documents and Settings/Administrator/My Documents/eb675e0fe214ca366159f351.jpg.gif";
//前面无需加"\"
%>
<img src="<%=s %>" />
//此处要写输出s,不然html并不能识别s变量
以实验过,完全能够通过
<%
String s="hx.jpg";
%>
<img src="D:/wwwjsp/picture/"+<%=s %>></img>