Reputation: 5585
I am facing problem while creating spring
mvc
project, my JSP
page is not rendered as expected below is code
my controller is
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping("/welcome")
public ModelAndView helloWorld(){
ModelAndView model=new ModelAndView("HelloPage");
model.addObject("msg","hello page");
return model;
}
}
jsp page is
<%@ 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">
<title>Insert title here</title>
</head>
<body>
<h2> {$msg}</h2>
</body>
</html>
below is output
Upvotes: 0
Views: 233
Reputation: 26961
You almost got it, but you have a typo here:
<h2> {$msg}</h2>
Spring uses ${nameOfAttr}
to refer bean/model attributes, so... you must write:
<h2> ${msg}</h2>
And your message will display as expected. For further info please check this link
Upvotes: 3