将模型属性传递给JSP中的javascript函数

时间:2013-09-06 00:23:00

标签: jsp spring-mvc

我正在研究Spring MVC。对JSP的知识非常有限......

我的控制器:

public ModelAndView handleRequest(HttpServletRequest request) {
    ModelAndView mv = new ModelAndView("investigate");
    mv.addObject("model", Model);
    return mv;
}

我的模特:

public class Model {    
public String research = "research";

public String getResearch() {
    return research;
}

public void setResearch(String research) {
    this.research = research;
}   
}

我的观点:

<button id="plotbtn" onclick = "myFunction(${model.research})">plot</button>

但它不起作用。你能指出如何纠正它吗?感谢

1 个答案:

答案 0 :(得分:2)

试试这个:

<button id="plotbtn" onclick = "myFunction('${model.research}')">plot</button>