我正在尝试将旧版应用程序转换为spring,我们有一个mvc模块,其网址为http://localhost:8080/MyApp/index .jsp
以前,该页面用于获取web.xml的负载,当我将应用程序转换为spring mvc配置时,使用index.jsp访问url并抛出404时。我可以使用/ index生成url并呈现索引使用spring的.jsp文件,不会在网址中显示.jsp。但是我的问题是使用.jsp保存URL的客户端会出错。
@EnableWebMvc
@ComponentScan(basePackages="com.app")
public class ClientWebConfigurer implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
public class ClientWebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx
= new AnnotationConfigWebApplicationContext();
ctx.register(ClientWebConfigurer.class);
ctx.setServletContext(servletContext);
ServletRegistration.Dynamic servlet = servletContext.addServlet(
"client-dispatcherServlet", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
感谢您的帮助。