【问题标题】:how to read the already existing bean in jstl|form?如何在 jstl|form 中读取已经存在的 bean?
【发布时间】:2012-10-07 16:44:06
【问题描述】:

我有简单的 SpringMVC 表单,我想通过 pbid 检索我已经拥有的 bean。问题是服务器端我可以得到已经设置的bean,但是jsp端总是得到新的bean。我可以使用 @ModelAttribute("productbean") 接收一些参数来获取服务器端的 bean 存储吗?怎么做? jstl|form 似乎总是得到新的形式

<form:form method="post" modelAttribute="productbean" action="">
<table>

    </tr>

    <tr>
        <td width="118"><form:label for="name" path="name" > Production Name:</form:label></td>
        <td colspan="2"><form:hidden path="pbid"/><form:input path="name" type="text" size="50" /></td>
    </tr>
...

我的控制器是这样的:

@RequestMapping(value="/createproduct", method=RequestMethod.GET)
public  String getProduct(HttpServletRequest req, Model model, 
        @RequestParam(value = "pbid", required = false, defaultValue = "") String spbid) throws MalformedURLException {
    UUID pbid;
    if(spbid.isEmpty())pbid=UUID.randomUUID();
    else pbid=UUID.fromString(spbid);
    ProductBean tmp;
    if(!products.containsKey(pbid)){
        tmp=createbean();
        pbid=tmp.getPbid(); 
        System.err.println("============new productbean===============\n");
    }else{
        tmp=products.get(pbid);
        System.err.println(tmp.getMpf().size());
        System.err.println(tmp.getMpf().printFileNameList());
    }
 .....

@ModelAttribute("productbean")
public ProductBean createbean(){
    ProductBean productbean=new ProductBean(context.getRealPath(filepath));
    products.put(productbean.assignID(), productbean);
    return productbean;
}

【问题讨论】:

    标签: spring spring-mvc jstl modelattribute


    【解决方案1】:

    在类上添加会话属性注释

    @SessionAttributes("productbean")
    @controller
    public class test() {
    }
    

    【讨论】:

    • 这似乎可行,但春天给了我:错误 [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/mvc].[Spring MVC Dispatcher Servlet]] (http-localhost-127.0.0.1-8080-3) Servlet.service() for servlet Spring MVC Dispatcher Servlet 抛出异常:java.lang.NoSuchMethodException: java.util.UUID.() 错误:
    • 你能告诉我我在哪里写的 UUID 初始化方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多