大家好,我在页面上写导入的时候是这样取的:<input type="file" name="excelFile" >
<input type="button" id="importFile" name="importFile" value="导入" onclick="importdemo();"/>
我用了type="file",那么我在后台怎样得到它呢?? 举个小例子吧,然后把还需要配置什么都说说,谢谢啦

解决方案 »

  1.   

    用jxl控件把,首先用<input type="file"> 获取文件的路径,得到路径后,在通过jxl实现导入就可以了。。
      

  2.   

    呵呵  不好意思  我忘说了 我用的是poi组件。
      

  3.   

    以前的例子:
    jsp文件:<input type="file" name="icon" style="width:200;height:25" />ACTION文件:
    //封装上传文件域的属性
    private File icon;
    //封装上传文件类型的属性
    private String iconContentType;
    //封装上传文件名,该文件的路径不包括
    private String iconFileName;
    private IMemberService memberService;

    public String execute() throws MemberServiceException{

    ServletContext sc=ServletActionContext.getServletContext();
    if(icon!=null&&icon.exists()){
    System.out.println("path1!!!!!");
    String path=sc.getRealPath("/");
    System.out.println("path:"+path);
    File dir=new File(path+"/images/"+this.nickName);
    if(!dir.exists()){
    dir.mkdir();
    }
    // File target=new File(dir.getPath()+"/"+iconFileName);
    try {
    /*FileUtils.copyFile(icon, target);*/
    FileInputStream fis=new FileInputStream(icon);
    FileOutputStream fos=new FileOutputStream(dir.getPath()+"/"+iconFileName);
    byte[] buffer=new byte[4096];
    int count=0;
    while((count=fis.read(buffer,0, buffer.length))!=-1){
    fos.write(buffer,0,count);
    }
    fos.flush();
    fis.close();
    fos.close();
    } catch (IOException e) {
    e.printStackTrace();
    ServletActionContext.getRequest().setAttribute("message", e.getMessage());
    return "failure";
    }
    }
    info.setIcon("/images/"+this.nickName+"/"+iconFileName);
    }
      

  4.   

    晕死了,自己解决了,我原来在后台用的是动态form接收的,但是我这嫌配置麻烦,就想用别的方法试验下,现在用隐藏域就可以传过去了,在运行,我导入的时候excel文件里面有就2行数据,不算表头。结果我在运行:
             int firstNum = sheet.getFirstRowNum();
         int lastNum = sheet.getLastRowNum();发现firstNum = 0,lastNum = 5,真晕啊,这是poi组件带的方法,我怎么才能改对呢??
      

  5.   

    结果我在运行: 
            int firstNum = sheet.getFirstRowNum(); 
        int lastNum = sheet.getLastRowNum(); 发现firstNum = 0,lastNum = 5,真晕啊,这是poi组件带的方法,我怎么才能改对呢??
    你想要啥?