springmvc访问html
❶ Spring MVC 直接访问 WEB-INF下的静态页面怎么在配置文件中配置,求大神解答
注意配置的时候如下规则
1、页面jsp(html等)的访问必须走controller的访问和跳转
2、css、js等可以直接通过地址去访问不需要走后台控制器
3、怎么处理的,可以配置访问限制。也就是放开对css、js等静态资源的访问,动态资源(.jsp用控制器去访问),参考连接网页链接
❷ springmvc 配置了跳转到jsp页面 怎么实现跳转到html页面
先看controller:
@RequestMapping(value = "/{id}/view", method = RequestMethod.GET, proces = "text/html")
public String getPostByIdHtml( @PathVariable String id) throws IOException {
return "/resources/Post.html";
}
再看配置:
@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan({ "com.my.web.api"})
@ImportResource("classpath:db-context.xml")
public class ApiServletConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/resources/");
internalResourceViewResolver.setSuffix("*.html");
return internalResourceViewResolver;
}
}