error set

When Chinese is used as a url variable, before initiating a request, the uri becomes a hexadecimal bytecode, and a character conversion is performed in the background when it is accepted.
String namef=new String(name.getBytes("ISO-8859-1 "),"UTF-8");
Tracking problems: Import the source code and problems, or check online directly.
java.lang.StringIndexOutOfBoundsException: String index out of range: -213

Since the object field to be converted has garbled characters, the json string was truncated when converting to json. The solution to the

garbled characters: String namef=new String(name.getBytes
when assembling in the java background

("ISO-8859-1"),"UTF-8");


@POST
    @Path("logs/EventId")
    @Produces(ContentType.APPLICATION_JSON_UTF_8)
    @Consumes(ContentType.APPLICATION_JSON_UTF_8)
    public long saveEventNameId(@Context HttpServletRequest request ) throws ManoException
    {
        try
        {
        EventNameId operationLog = new EventNameId();
            operationLog.setEventId(request.getParameter("Event-Id"));
            String name =request.getParameter("Event-Name");
            String namef=new String(name.getBytes("ISO-8859-1"),"UTF-8");
            operationLog.setEventName(namef);
            operationLogLS.insertEventOne(operationLog);
            return operationLog.getId();
        }
        catch (Exception ex)
        {
            LOG.error(ex.getMessage(), ex);
            throw new ManoException(ex);
        }
    }

///这个偏前台url

当然也可以在url中加参数

  Client client = ClientBuilder.newClient();
            WebTarget target = client.target(url);
   // target = target.queryParam("useUnicode", "true");
             // target = target.queryParam("characterEncoding", "utf8 ");

This is the hexadecimal java code conversion with url, but because the WebTarget package is too strong, even if it is converted into Chinese, it will be converted back to

String a= URLEncoder.encode("%E5%8B" );
// String output = URLDecoder.decode(a, "UTF-8");
// System.out.println(URLDecoder.decode(output,"UTF-8"));

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326987505&siteId=291194637