简体   繁体   English

在 angular2 发布请求中显示 而不是 ü

[英]Displaying � instead of ü in angular2 post request

I have facing issue in displaying German Umlaut characters in HTML page of angular2 application.我在 angular2 应用程序的 HTML 页面中显示德语变音字符时遇到问题。 My backend services are in java and it returns json String.我的后端服务在 Java 中,它返回 json 字符串。

This is the response of the post request which is shown in network tab.这是网络选项卡中显示的发布请求的响应。 and it shows ü character properly .它正确显示 ü 字符。

在此处输入图片说明

but if i console the data from below snippet, it shows both in HTML ui and console .但是如果我从下面的代码段中控制数据,它会在 HTML ui 和 console 中显示 。

    getStackById(project: string, stackId: string, ibsessionid: string) {
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    return this.http.post('http://' + this.ip + ':' + this.port + '/IBPublicationBuilder/MiddlewareServlet', 'project=' + project + '&stackid=' + stackId + '&ibsessionid=' + ibsessionid + '&method=getStackById', {
      withCredentials: true, headers: headers
    }).map(
      (res: Response) => {
         console.log(res);
        return res.json()}
      );
  }

console:安慰: 在此处输入图片说明

UI:用户界面: 在此处输入图片说明

Solved the issue with the below solution.使用以下解决方案解决了该问题。

Added添加

headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');

In the header and also Changed the server side.在标题中,也改变了服务器端。 As I mentioned my services were in java .正如我提到的,我的服务是在 java 中的。 Added添加

response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");

to my my response object.到我的响应对象。

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

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