向HTML“img src”选项添加高度或宽度时不加载java图像
当有高度时,图像不会加载。当我删除高度图像时,可以完美地加载原始图像大小。我只需要在网页中显示固定大小的图像。为什么我不能在代码中使用高度和宽度
<!DOCTYPE html>
<html>
<head>
<title>Listing Images</title>
</head>
<body>
<h1>Listing Images</h1>
<table border="1">
<tr>
<th>Preview</th>
<th>Available information</th>
<th>Update Information</th>
<th>Action</th>
<%
List<Files> files = (List<Files>) request.getAttribute("files");
String path = (String) request.getAttribute("path");
for (Files file : files) {
out.print("<tr><td><img src="+ path+file.getFileName()+"height='200'></td></tr>");}
%>
</table>
</body>
</html>
# 1 楼答案
在
src=
标记所在的out.print()
语句中,可能需要转义字符\"
我会试试这个
out.print("<tr><td><img src=\""+ path+file.getFileName()+"\"height='200'></td></tr>");