Reputation: 84
These are my classes.
WebConfig.java:
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.pluralsight")
public class WebConfig {
}
HelloController.java:
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping(value="/greeting")
public String sayHallo(Model model){
model.addAttribute("greeting", "Good morning Dhaka");
return "hello.jsp";
}
}
WebAppInitializer.java:
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("*.html");
}
private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation("com.pluralsight.WebConfig");
return context;
}
}
This is the jsp page: hello.jsp:
<title>hello</title>
</head>
<body>
<h2>${greeting }</h2>
</body>
</html>
But...when I run this on server at localhost:8080/MyPage/greeting.html, then I get the output as : ${greeting}
How can I solve this problem , means , I want to show "Good morning Dhaka!".
Upvotes: 1
Views: 873
Reputation: 2649
Add this <%@ page isELIgnored="false" %>
at the top of your jsp page.
Upvotes: 1