先将文件名保存到request中,比如request.setAttribute("filename",filename);
然后在显示图片的页面:
<img src="<%=上传文件夹所在的路径+request.getAttribute("filename")%>" />

解决方案 »

  1.   

    public class FileAction extends Action {
    /*
    * Generated Methods
    *//**
    * Method execute
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return ActionForward
    * @throws IOException
    * @throws FileNotFoundException
    */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws FileNotFoundException, IOException {request.setCharacterEncoding("utf-8");
    DynaActionForm dform = (DynaActionForm) form;
    FormFile file = (FormFile) dform.get("file");
    if (file == null || file.getFileSize() <= 0) {
    return mapping.getInputForward();
    }String filename = file.getFileName();
    InputStream is = file.getInputStream();
    String uploadpath = servlet.getServletContext().getRealPath("/upload");
    System.out.println("路径1:"+uploadpath);
    OutputStream os = new FileOutputStream(uploadpath + "/" + filename);
    System.out.println("路径2:"+os);
    int bytes = 0;
    byte[] buffer = new byte[8192];
    while ((bytes = is.read(buffer, 0, 8192)) != -1) {
    os.write(buffer, 0, bytes);
    }
    os.close();
    is.close();
    file.destroy();
    request.setParameter("src",uploadpath + "/" + filename);
    return mapping.findForward("fileok");
    }
    fileok.jsp只写了body部分
    ------------------------------------------
    <img src="<%=request.getParameter("src")%>" />} 
      

  2.   

    还是不行哟!获取不了的!而且request.setParameter("src",uploadpath + "/" + filename);根本没有request.setParameter();报错的!
      

  3.   

    应该是request.setAttribute("src",uploadpath + "/" + filename);