我的 jsp 页面没有正确显示输出
My jsp page is not showing output properly
这些是我的类。
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;
}
}
这是 jsp 页面:
hello.jsp:
<title>hello</title>
</head>
<body>
<h2>${greeting }</h2>
</body>
</html>
但是...当我在 localhost:8080/MyPage/greeting.html 的服务器上 运行 时,我得到的输出为:
${问候语}
我该如何解决这个问题,也就是说,我想展示 "Good morning Dhaka!"。
将此 <%@ page isELIgnored="false" %>
添加到 jsp 页面的顶部。
这些是我的类。
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;
}
}
这是 jsp 页面: hello.jsp:
<title>hello</title>
</head>
<body>
<h2>${greeting }</h2>
</body>
</html>
但是...当我在 localhost:8080/MyPage/greeting.html 的服务器上 运行 时,我得到的输出为: ${问候语}
我该如何解决这个问题,也就是说,我想展示 "Good morning Dhaka!"。
将此 <%@ page isELIgnored="false" %>
添加到 jsp 页面的顶部。