zoukankan      html  css  js  c++  java
  • Neither BindingResult nor plain target object for bean

     当你开发一个项目,如果你选择的是spring MVC 框架,而你在前台使用spring的标签时,那么你有可能出现在这个情况。

    javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute

    方法:1为抛出异常原因,2为异常解决方法。

    1.    原因:   进入spring:bind标签源码你可以看到

    Object target = requestContext.getModelObject(beanName);
       if (target == null) {
        throw new IllegalStateException("Neither BindingResult nor plain target object for bean name '" +
          beanName + "' available as request attribute");
       }

    beanName=    <spring:bind path="command.spjg">的绿色部分

    如果你是直接对某个页面进行请求,那么request中还没command这个对象

    2.

    在页面上加上

    <jsp:useBean id="command"  class="com.ztenc.proj.bean.AFRFOAP" scope="request" ></jsp:useBean>

    红色部分填上你的绑定类

    PS:虽不明,但觉厉~

    以上内容是转载、 接下来是我自己的原创解决方案:

    在controller处。加上:

    @ModelAttribute
    public Product get(@RequestParam(required=false) Long id) {
      return id==null?new Product():productService.findOne(id);
    }

    一切OK

  • 相关阅读:
    配置 L3 agent
    Why Namespace?
    虚拟 ​router 原理分析
    创建 router 连通 subnet
    用 config drive 配置网络
    cloud
    写在最前面
    使用apktool工具遇到could not decode arsc file的解决办法
    php-fpm优化
    解决官网下载jdk只有5k大小的错误
  • 原文地址:https://www.cnblogs.com/ChenJunHacker/p/4490483.html
Copyright © 2011-2022 走看看