0

i am new to Spring Mvc,so i have this simple question below

Code1:

@RequestMapping("/hello")
    public ModelAndView hello()
    {
        String str="Be happy!!!!!";
        return new ModelAndView("hello","message",str);
    }

In hello.jsp View Page ,when i print str then i get result as ${message}

code2:

@RequestMapping("/hello")
    public ModelAndView hello()
    {
        String str="Be happy!!!!!";
        return new ModelAndView("hellopage","message",str);
    }

but in hellopage.jsp i get result as Be happy!!!!!

so why above code1 does not print str string?

below is my view page jsp code and it is same for both hello.jsp and hellopage.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>
<body>
${message}
</body>
</html>
4
  • What error message does it throw ? Commented Oct 30, 2018 at 5:14
  • Please give a screen shot of your project structure Commented Oct 30, 2018 at 5:23
  • in hello.jsp View Page ,when i print str then i get result as ${message} and in hellopage.jsp i get result as Be happy!!!!! Commented Oct 30, 2018 at 5:25
  • @PiraiSudie Check my answer and let us know ! Commented Oct 30, 2018 at 5:36

2 Answers 2

1

In hello.jsp put this expression <%@ page isELIgnored="false"%> at the top. Sometimes expression language automatically off for page

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

1 Comment

That's why I suggest you to use to expression !
1

The EL expression doesn't get evaluated? That can have one or more of the following causes:

  1. Application server in question doesn't support JSP 2.0.
  2. The web.xml is not declared as Servlet 2.4 or higher.
  3. The @page is configured with isELIgnored=true.
  4. The web.xml is configured with true in .

In your case it looks like case no 3. Try to put isElIgnored=false in your jsp file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.