在angular2 post请求中显示 而不是ü

时间:2022-06-07 12:07:20

I have facing issue in displaying German Umlaut characters in HTML page of angular2 application. My backend services are in java and it returns json String.

我在angular2应用程序的HTML页面中显示德语变音字符时遇到问题。我的后端服务是在java中,它返回json String。

This is the response of the post request which is shown in network tab. and it shows ü character properly .

这是发布请求的响应,显示在网络选项卡中。它正确地显示了ü字符。

在angular2 post请求中显示 而不是ü

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:在angular2 post请求中显示 而不是ü

安慰:

UI: 在angular2 post请求中显示 而不是ü

用户界面:

1 个解决方案

#1


0  

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 . Added

在标题中也改变了服务器端。正如我所提到的,我的服务是在java中。添加

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

to my my response object.

到我的回应对象。

#1


0  

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 . Added

在标题中也改变了服务器端。正如我所提到的,我的服务是在java中。添加

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

to my my response object.

到我的回应对象。