java如何解码接收到的url参数抛出BeanParam

2022-01-21 00:00:00 decoding java jax-rs jersey urldecode

我收到对此网络服务的GET响应

I receive a GET response to this web service

@GET
@Path("/nnnnnn")
public Response pfpfpfpf(@BeanParam NNNNNN n)

NNNNN 类有:

@QueryParam("parameter")
private String parameter;

对于那个参数有一个get和set.

And for that parameter there is a get and set.

我使用 查询参数 在 get 上发送请求,它会自动绑定到我的选项 NNNNN,一切都很好.

I send a request on a get with a query parameter and it is being bind automatically to my option NNNNN, everything is great.

但是,现在我在查询 url 中发送日语字符串.我在发送之前使用 UTF-8 对参数进行编码,我必须使用 UTF-8 对其进行解码.

but, now i am sending Japanese strings in the query url. I encode the paramter by UTF-8 before sending, and I have to decode them using UTF-8.

但我的问题是应该在哪里调用 URLDecoder?我试图在该参数的 getter 中调用它,但它没有用,我一直有类似 C3%98%C2%B4%C3%98%C2 之类的东西,而不是日文字符

but my question is where should I call the URLDecoder? i tried to call it in the getter of that parameter, but it didn't work, i kept having something like C3%98%C2%B4%C3%98%C2 instead of the Japanese characters

推荐答案

适合我的解决方案是:

在 servlet 上,我应该这样做:

on the servlet, i should do this:

request.setCharacterEncoding("UTF-8");

然后在 html 页面上我必须添加这个:

and then on the html page i had to add this:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

相关文章