我如何从jsp读取文件名并将其用作图像的src?
<%
System.out.println("Content Type ="+request.getContentType());
String fileBasePath = "c:/temp"; //Base path where you wanto store the files...
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(100000000);
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
try{
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
if(!fi.isFormField()) {
File fNew= new File(fileBasePath, new File(fi.getName()).getName());
System.out.println(fNew.getAbsolutePath());
fi.write(fNew);
}
else {
System.out.println("Field ="+fi.getFieldName());
}
}
}
catch(Exception e)
{
System.out.println(e);
}
%>
<%
System.out.println("Content Type ="+request.getContentType());
String fileBasePath = "c:/temp"; //Base path where you wanto store the files...
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(100000000);
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
try{
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
if(!fi.isFormField()) {
File fNew= new File(fileBasePath, new File(fi.getName()).getName());
System.out.println(fNew.getAbsolutePath());
fi.write(fNew);
}
else {
System.out.println("Field ="+fi.getFieldName());
}
}
}
catch(Exception e)
{
System.out.println(e);
}
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个
Servlet
,它将图像作为InputStream
获取,并将其写入响应的OutputStream
,然后在< 中调用该 servlet ;img src>
。例如,
可以
在此处找到一个基本示例。
Create a
Servlet
which gets the image asInputStream
and writes it to theOutputStream
of the response and then call that servlet in the<img src>
.E.g.
with
A basic example can be found here.