1
Это мои классы.Моя страница 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>
... Но когда я запускаю это на сервере на локальном хосте: 8080/MyPage/приветствие .html, то я получаю вывод как: $ {приветствие}
Как решить эту проблему, значит, я хочу как «Доброе утро, Дакка!».
Проблема решена. –
В чем секрет этого? – vigamage