我使用hibernate在数据库中保存图像路径并将图像存储在本地文件夹中但是当我无法在另一个jsp页面上显示图像时
这是我的servlet代码
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String relativePath = getServletContext().getInitParameter("file-upload");
System.out.println(relativePath);
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
return;
}
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(MAX_MEMORY_SIZE);
factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
ServletFileUpload upload = new ServletFileUpload(factory);
// Set overall request size constraint
upload.setSizeMax(MAX_REQUEST_SIZE);
String savePath = relativePath + File.separator + DATA_DIRECTORY; //specify your path here
File fileSaveDir=new File(savePath);
if(!fileSaveDir.exists()){
fileSaveDir.mkdir();
}
try {
// Parse the request
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
fileName = new File(item.getName()).getName();
System.out.println( fileName);
String filePath = fileSaveDir + File.separator +fileName;
File uploadedFile = new File(filePath);
System.out.println(filePath);
// saves the file to upload directory
item.write(uploadedFile);
Session sess=null;
try
{
System.out.println("file path is:="+filePath);
sess=SessionFactoryCreation.getSessionFactory().openSession();
sess.beginTransaction();
UploadBean ubBean=new UploadBean();
ubBean.setImagepath(filePath);
sess.save(ubBean);
sess.getTransaction().commit();
}
catch(Exception ex)
{
ex.printStackTrace();
sess.close();
}
}
}
} catch (FileUploadException ex) {
throw new ServletException(ex);
} catch (Exception ex) {
throw new ServletException(ex);
}
}
现在我有一个jsp页面,我有链接它将打开另一个jsp页面,所有图像都应显示在...