繁体   English   中英

如何从txt / html,Ubuntu,tomcat8更改响应标头内容类型

[英]How to change Response Header Content-Type from txt/html, Ubuntu, tomcat8

我正在调用API以返回带有所有所需对象(注释)的JSON

$( document ).ready(function() {
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    if (xhr.readyState == XMLHttpRequest.DONE) {
      var response = xhr.responseText;
               //do stuff with response        
    }
    xhr.open('GET', 'http://mydomain:8080/notes/all', true);
    xhr.send(null);
  });

HTTP请求:

@RequestMapping(value = {"/all"}, method = RequestMethod.GET, produces = "application/json")
public  @ResponseBody List<Note> getAllNotes() {
    return noteService.getAllNotes();
}

当我在Mac上本地运行时,一切正常。 我的Response标头具有Content-Type:application / java,而Request接受它。

但是,当我将.war上传到Ubuntu 16.04服务器时,Request标头的Content-Type更改为txt/html ,我得到了

404页面不存在

我在两台机器上都使用tomcat8.5.5

如何指定/更改请求标头的内容类型?

标头图片:在远程上运行 的Ubuntu 和本地 苹果电脑

我注意到在index.html和notes.html两者中都有<script src="noteAPI.js"></script>声明。 我已经从index.html中删除了此声明,并且它起作用了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM