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?

3
  • 3
    I've seen several questions like this before, you might search those out. Here is one, here is another, and here is another. Commented Dec 22, 2011 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? Commented Dec 22, 2011 at 21:30
  • This answer: stackoverflow.com/questions/1529184/… may be helpful. Commented Dec 22, 2011 at 21:55

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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);
 }

2 Comments

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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.