file对象有getFilePath()这个方法

解决方案 »

  1.   

    我说一个简单的例子:
        jsp页面的代码  
        <htm:form action="upload.do" method="post" enctype="multipart/form-data">
       <html:file property="pic"/> <html:submit value="提交"/>
        </html>
       这里是通过property="pic" 浏览后把浏览的结果保存在这里.之后跳转到配置文件当中去,处理过后,
       保存在actionForm当中。
    在ActionForm 当中定义一个 private FormFile pic;并生成get, set.
    之后会转到Action 当中去。实例ActionForm 调用getPic() 需要获取途径就是getPic().getFileName();
        如果你需要在页面当中获取它的路径并显示路径的话,可以把路径保存在request中,然后转发到制定的jsp页面,
    就何以啦。
      
      

  2.   

    是想在浏览了图片后 图片就在提交页面显示 是不?如果是

    <script type="text/javascript">
      function imgchange(imgpath){
      var img=document.getElementById("img");
      img.src=imgpath.value;
      }
      </script>    <htm:form action="upload.do" method="post" enctype="multipart/form-data"> 
          <IMG src="" width="30" height="40" id="img"/><br>
        <html:file property="file" onchange="imgchange(this)"/>
        <br>
        </html>
      

  3.   

    如果你想传到服务器(Tomcat)中用这个看看
    String path = request.getRealPath(request.getServletPath());
    String pathname = path.substring(0, path.lastIndexOf("\\"));
    OutputStream out = new FileOutputStream(pathname + "\\images\\"+ filename);