我已经设置了一个spring boot应用程序,我正在尝试运行一个简单的mvc流程。但是JstlView类正在转发请求以将/WEB-INF/views/jsp/login.jsp
呈现给'dispatcherServlet',并且我得到以下日志: -
2015-10-25 17:43:06.143 DEBUG 6181 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.JstlView: name 'login'; URL [/WEB-INF/views/jsp/login.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2015-10-25 17:43:06.143 DEBUG 6181 --- [nio-8080-exec-1] o.s.web.servlet.view.JstlView : Added model object 'username' of type [java.lang.String] to request in view with name 'login'
2015-10-25 17:43:06.146 DEBUG 6181 --- [nio-8080-exec-1] o.s.web.servlet.view.JstlView : Forwarding to resource [/WEB-INF/views/jsp/login.jsp] in InternalResourceView 'login'
2015-10-25 17:43:06.148 DEBUG 6181 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
我的Application.java运行spring boot应用程序: -
@Configuration
@EnableAutoConfiguration
@ComponentScan("com.thinksmallgroup.projectmanager")
@EnableWebMvc
public class Application {
@Bean
public DispatcherServlet dispatcherServlet() {
return new DispatcherServlet();
}
@Bean
public ServletRegistrationBean dispatcherRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet(), "*.do");
return registration;
}
/**
* main method to start the application.
*
* @param args
* any arguments passed while running the application.
*/
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
我的WebConfig.java
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/views/jsp/", ".jsp");
registry.order(Ordered.HIGHEST_PRECEDENCE);
}
}
控制器: -
@Controller
public class LoginController {
/**
* @param name
* @return String
*/
@RequestMapping("/login.do")
public ModelAndView login(@RequestParam(required = false) String name) {
return new ModelAndView("login", "username", "VIneet");
}
我的login.jsp: -
<html>
<head><title>Think Small Group</title></head>
<body>
<h1>Project Manager</h1>
<p>Welcome ${username}</p>
</body>
</html>