本帖最后由 woshixinde 于 2010-05-30 12:56:19 编辑

解决方案 »

  1.   

    Messages: java.lang.String cannot be cast to [B 不是提示是强制类型转换错误吗?自己好好在检查下代码咯
      

  2.   

    java.lang.String cannot be cast to [B 
    字符串无法被转换成字节数组
    看看你给byte[] context;赋值的时候是否错了.?  String.getBytes()赋值
      

  3.   

    帅哥 可是他没有执行那个setContext()方法啊 为什么会出这个错误啊
      

  4.   

    我在你的代码中没有看到有调用setContext喔.!  你自己瞅下看你贴出来的是不是没有
      

  5.   

    恩 好的 那我把它全弄出来吧 非常感谢你哈!兄弟!
    这个是Action里面的  public String add(){
         Document document=new Document();
         if(contextFile!=null){
             document.setContext(this.fileToByteArray(contextFile));
             System.out.println("fdsfdsfdasfdsa");
         }
         document.setDescription(description);
         document.setTitle(title);
         documentManager.addDocument(document, workflowId, this.currentUser().getId());     return "add_success";
        }这个是DocumentManager里面的addDocument()方法:
    public void addDocument(Document document, int workflowId, int userId) {
            System.out.println(0);
    //添加公文
    document.setCreateTime(new Date());                this.getHibernateTemplate().save(document); document.setWorkflow((Workflow)this.getHibernateTemplate().load(Workflow.class, workflowId));
                    document.setCreator((Users)this.getHibernateTemplate().load(Users.class, userId));
            document.setStatus(Document.STATUS_NEW);
    //        
    //        this.getHibernateTemplate().save(document);
    //        System.out.println(5);        //添加流程实例
    long processInstanceId = workflowManager.addProcessInstance(document.getWorkflow().getName(), document.getId());
      System.out.println(6);
    //绑定流程实例的标识到公文对象
    document.setProcessInstanceId(processInstanceId);
      System.out.println(7);
    getHibernateTemplate().update(document);
      System.out.println(8);
    }帅哥 帮我看看哈!
      

  6.   

    我明白你是什么意思了.!
    是这样的.!  Struts2的Action中有的Document属性, 然后从页面中填充请求参数.!
    那么你页面上获取context应该是document.context吧.? 这个跟你是否添加了没有关系.!
    只要你有name为document.context的请求参数过来,就会填充, 没有填值是"", 就像你request.getParameter(name),有这个name,没值,就是""是一样的道理
    那么把一个空字符串转成byte,能不错吗?
      

  7.   

    Struts2虽然有自动转换类型,但是好像String---->byte[]还没这一说..
    因为后台如果是数组的属性,那么在前台上是有多个这样的name与之对应的.!  
      

  8.   

    谢谢你们哈! 我已经解决了 怪我啊  hibernate 注解 注解到别的字段去了杯具 3天就这样没了  浪费生命啊!不说了 结贴了!