Since the functions related to DispatcherServlet are implemented by another department of my company, I can only complete the specific business classes of the back-end and the front-end, so I cannot directly return byte[] to the front-end.
So I use
Base64.getUrlEncoder().encodeToString(bytes);
response.put("data", data);
to return a RESTful json response to my front-end.
But in Java encodeToString
, BASE64 util converts the bytes to BASE64 bytes and then returns a String based on ISO_8859_1
...
First, How can I convert the string to the ISO_8859_1
byte[]?
Second, How can I decode the byte[] encoded by BASE64?
in frontEnd,
this.http.pdf(data).subscribe(
resp => {
const data = WhatShouldTheMethodBe(respo['data']); //What should the method be?
let blob = new Blob([data], { type: 'application/pdf' });
let url = window.URL.createObjectURL(blob);
let pwa = window.open(url);
if (!pwa || pwa.closed || typeof pwa.closed == 'undefined') {
alert('Please disable your Pop-up blocker and try again.');
}
}
);
Thanks a lot.