Restlet参考解码"#"标志

时间:2016-06-06 04:26:55

标签: java web-services restlet

我设置了如下URI:

router.attach("/pmap/campaign/{campaign}/staffCat/{staffCat}/isp/{isp}", PMAPResource.class);

在PMAPResource.class中,我有以下代码:

public Representation represent()
{
    String campaignID   = (String) this.getRequestAttributes().get("campaign");
    String staffCat     = Reference.decode((String) this.getRequestAttributes().get("staffCat"));
    String ispID        = (String) this.getRequestAttributes().get("isp");
}

staffCat字段是用户手动输入,可以是任何内容。一些例子是:

BAA2(A)
BAB1#(A)
BA B1

它适用于大多数情况,直到它到达#符号,返回404 Not Found错误。控制台转储显示以下/fwd-PMAP/pmap/campaign/1/staffCat/BAB1

我应该怎么做以阅读"#"所以我可以得到BAB1#(A)原样吗?

1 个答案:

答案 0 :(得分:1)

#在网址中具有特殊含义。必须逃脱。

网址中实际上有许多特殊字符,因此在客户端构建网址时,您应始终转义任意文字。

在这种特殊情况下,客户端发送的正确URL类似于:

/fwd-PMAP/pmap/campaign/1/staffCat/BAB1%23(A)/isp/XXX

同样,这是一个需要在客户端修复的问题。服务器将为您解码%23