1

Possible Duplicate:
JSP: EL expression is not evaluated

I have the following code in my controller.

@RequestMapping(value = "/sum", method = RequestMethod.GET)
public String sum(@RequestParam("input1") String value1,
        @RequestParam("input2") String value2, ModelMap model) {
    model.addAttribute(
            "msg",
            Integer.toString(Integer.parseInt(value1)
                    + Integer.parseInt(value2)));
    return "index";
}

Following is my view:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
<body>
<h2>Hello World!</h2>
<h2>Movie Name : <c:out value="${msg}"></c:out></h2>    
</body>
</html>

But my output is

Hello World!
Movie Name : ${msg}

Where am i wrong?

Community
  • 1
  • 1
Akhil K Nambiar
  • 3,835
  • 13
  • 47
  • 85
  • 3
    I've seen several questions like this before, you might search those out. [Here is one](http://stackoverflow.com/questions/793983/jsp-el-expression-is-not-evaluated), [here is another](http://stackoverflow.com/questions/2168832/expression-language-in-jsp-not-working), and [here is another](http://stackoverflow.com/questions/1721518/el-expressions-wont-executed-in-tomcat-5-5-but-working-in-tomcat-6-0-20/1721665). – Beau Grantham Dec 22 '11 at 21:05
  • 1
    Are you aware that Spring can do type conversion for you and that you can make the method parameters `Integer`, avoiding the manual type conversion? – Dave Newton Dec 22 '11 at 21:30
  • This answer: http://stackoverflow.com/questions/1529184/jsps-not-displaying-objects-from-model-in-spring may be helpful. – Bill Dec 22 '11 at 21:55

2 Answers2

2

This is because jstl library is not available. Either copy it to WEB-INF/lib or copy that directly to Tomcat/lib directory and restart Tomcat.

Mobiz Tech Team
  • 182
  • 3
  • 12
0

You're returning a View String "index" but your model is not being sended/attached to the response view, so $msg is not found/bound in your JSP

Try this

 @RequestMapping(value = "/sum", method = RequestMethod.GET)
 public ModelAndView sum(@RequestParam("input1") String value1, @RequestParam("input2") String value2, ModelMap model) {
        model.addAttribute( "msg", Integer.toString(Integer.parseInt(value1) + Integer.parseInt(value2)));
        return new ModelAndView("index", model);
 }
Carlos Quijano
  • 1,566
  • 15
  • 23
  • I don't believe this is correct--you can return a string to indicate the view to be rendered, objects in the model are still exposed. – Dave Newton Dec 22 '11 at 21:45
  • The view would simply not print anything if this were the case. Spring carries `model` forward when returning a `String`, so changing the method to return a `ModelAndView` is not necessary in this case. – Beau Grantham Dec 22 '11 at 21:47