Edmond
Edmond

Reputation: 644

Pass a model property to a javascript function in JSP

I'm working on Spring MVC. Have very limited knowledge in JSP...

My controller:

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

My Model:

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

public String getResearch() {
    return research;
}

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

My view:

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

but it's not working. Can you point out how to correct it? Thanks

Upvotes: 0

Views: 2584

Answers (1)

Alex
Alex

Reputation: 11579

Try this:

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

Upvotes: 2

Related Questions