2
我想用Freemarker和Sitemesh來使用SpringBoot。爲什麼我的瀏覽器下載文件而不是渲染SpringBoot&Sitemesh輸出?
當我在應用程序處理請求時轉到URL時,會生成數據加載和HTML輸出,但由於某種原因,瀏覽器已決定要下載文件(其中包含正確的內容),而不是比渲染它作爲一個頁面。
這是工作一段時間後,麻煩是我不知道我已經做了哪些改變打破了它!
SiteMesh的過濾器:
@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對象... 接受:文本/ HTML,應用/ XHTML + xml的,APPLICAT離子/ XML; Q = 0.9,圖像/ WEBP,/; Q = 0.8
在響應報頭: 內容類型:應用/八位字節流;字符集= UTF-8
我想內容類型是問題....只是要找到爲什麼它被設置爲這樣。
什麼是您收到的http頭的Content-Type值? –
你是對的@OrtomalaLokni內容類型不正確,只能嘗試並找出原因 – DaFoot
是否可以在github下提供[mcve](http://stackoverflow.com/help/mcve)? –