不是从数据库中读取,是直接从文件夹中读取
5 个解决方案
#1
#2
<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);
byte[] buf = new byte[100]; //缓冲区大小
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
%>
#3
牛叉
#4
多谢,我想看下,多谢,我想看下多谢,我想看下多谢,我想看下
#5
<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);
byte[] buf = new byte[100]; //缓冲区大小
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
%>
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);
byte[] buf = new byte[100]; //缓冲区大小
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
%>
#1
#2
<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);
byte[] buf = new byte[100]; //缓冲区大小
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
%>
#3
牛叉
#4
多谢,我想看下,多谢,我想看下多谢,我想看下多谢,我想看下
#5
<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);
byte[] buf = new byte[100]; //缓冲区大小
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
%>
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);
byte[] buf = new byte[100]; //缓冲区大小
int len = 0;
while ((len = fis.read(buf)) != -1) {
sos.write(buf, 0, len);
}
sos.flush();
sos.close();
fis.close();
%>