小弟在做将excal表导入数据库的项目 遇到个小问题,就是不能得到绝对路径,请各位大牛指教!以下是代码片段
form action="servlet/tomysqlservlet2" method="post">
选择文件1:
<input type="file" name="excel" />
<input type="submit" value="导入" />
</form>
上面是jsp。public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
   into in=new into();
   excel ex=new excel();
   String path=request.getParameter("excel");
   System.out.println(path);
   File file=new File(path);
   List ls=ex.addCustomerAssign(file);
   Iterator iter=ls.iterator();
   while(iter.hasNext())
   {
    mynews ms=(mynews)iter.next();
    if(in.insertexcel(ms))
     System.out.println("成功");
    else
     System.out.println("失败");
   }
}
这里是servlet,我想在System.out.println(path);处测试下得到的path,但是每次打印出来的都是“ddd。xls”,而我想得到的是他的绝对路径d:\ddd。xls  请问如何解决!

解决方案 »

  1.   

    String path=request.getParameter("excel");??
    得到的是个字符串. 你应该得到文件File对象.然后获得路径.
      

  2.   

    我就是想直接得到这个字符串 然后给file啊!莫非这样不行?
      

  3.   

    String path=request.getParameter("excel");
    得到的应该是文件在客户端的路径,服务器自然无法得到咯
      

  4.   

    没听懂,我现在只需要得到他的绝对路径就行了比如这样就可以完成
     String path="d:\\ddd.xls"; 把path写死。
      

  5.   

    导入的  应该是你 服务器上的路径   你应该定义一个  upload path  存放  上载的文件 
      

  6.   

    String path=request.getParameter("excel");在IE6和IE7能够获得全路径,IE8、Firefox(目前最新版本)不能!这个体现了安全性的提升! 客户端没有发送这个值过来,服务器是获取不到的,你可以改下IE配置