Spring boot 为什么我的浏览器下载文件而不是呈现SpringBoot&;Sitemesh输出?
我正在尝试将SpringBoot与Freemarker和Sitemesh结合使用 当我在应用程序处理请求时转到URL时,会加载数据并生成HTML输出,但出于某种原因,浏览器决定下载文件(其中包含正确的内容),而不是将其呈现为页面 这是工作了一段时间,麻烦的是我不知道我所做的改变打破了它 Sitemesh过滤器:Spring boot 为什么我的浏览器下载文件而不是呈现SpringBoot&;Sitemesh输出?,spring-boot,sitemesh,Spring Boot,Sitemesh,我正在尝试将SpringBoot与Freemarker和Sitemesh结合使用 当我在应用程序处理请求时转到URL时,会加载数据并生成HTML输出,但出于某种原因,浏览器决定下载文件(其中包含正确的内容),而不是将其呈现为页面 这是工作了一段时间,麻烦的是我不知道我所做的改变打破了它 Sitemesh过滤器: @WebFilter public class SitemeshFilter extends ConfigurableSiteMeshFilter { private static f
@WebFilter
public class SitemeshFilter extends ConfigurableSiteMeshFilter {
private static final Logger LOG = Logger.getLogger(SitemeshFilter.class);
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
LOG.debug("SiteMeshFilter creation");
builder.addDecoratorPath("/*", "/templates/main.ftl")
.addExcludedPath("/h2console/*");
}
}
应用程序:
@ServletComponentScan
@SpringBootApplication
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class ClubManagementApplication {
private static Logger LOG = Logger.getLogger(ClubManagementApplication.class);
public static void main(String[] args) {
SpringApplication.run(ClubManagementApplication.class, args);
}
}
控制器的代码段:
@Controller
public class ClubController {
@Autowired
ClubService clubService;
@RequestMapping(value = {"Club/{id}","club/{id}"})
public ModelAndView viewClub(@PathVariable("id") int clubId) {
ModelAndView mv = new ModelAndView("club");
....
return mv;
}
}
编辑:
从控制器中的HttpServletRequest对象。。。
接受:text/html、application/xhtml+xml、application/xml;q=0.9,图像/webp,/;q=0.8
在响应标题中:
内容类型:应用程序/八位字节流;字符集=UTF-8
我想问题出在内容类型上……只是要找出为什么会这样设置。如果有人无意中发现这个问题,我将模板文件从ftl更改为html扩展名,然后它突然醒了过来
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
LOG.debug("SiteMeshFilter creation");
//builder.addDecoratorPath("/*", "/templates/main.ftl");
builder.addDecoratorPath("/*", "/templates/main.html");
}
你收到的http头的内容类型值是多少?你说得很对@OrtomalaLokni内容类型不正确,只需尝试找出为什么可以在github下提供一个?这可能很棘手,我会看看我能做些什么,但不能保证