首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么不允许%

为什么不允许%
EN

Stack Overflow用户
提问于 2013-02-21 22:14:46
回答 2查看 1.3K关注 0票数 1

如果我将密码输入为Admin$&%^Admin$&^%,那么我的ajax调用可以正常工作,但是如果我像这样输入Admin$!%Admin$!%^。ajax调用抛出以下异常.....

请帮帮我,因为我找不到这个问题的根本原因。

代码语言:javascript
运行
复制
INFO: Character decoding failed. Parameter [txt_password] with value [Admin$!%] has been ignored. No
te that the name and value quoted here may be corrupted due to the failed decoding. Use debug level
logging to see the original, non-corrupted values.
java.io.CharConversionException: EOF
        at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:80)
        at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:46)
        at org.apache.tomcat.util.http.Parameters.urlDecode(Parameters.java:410)
        at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:370)
        at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:217)
        at org.apache.catalina.connector.Request.parseParameters(Request.java:2647)
        at org.apache.catalina.connector.Request.getParameter(Request.java:1106)
        at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:355)
        at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:158)

在探索过程中,我发现:

代码语言:javascript
运行
复制
Special characters are not allowed inside the query string. They must be replaced by a "%" followed by the ASCII code in Hex. E.g., "~" is replaced by "%7E", "#" by "%23" and so on. Since blank is rather common, it can be replaced by either "%20" or "+" (the "+" character must be replaced by "%2B"). This replacement process is called URL-encoding, and the result is a URL-encoded query string. 

那么这是否意味着我们不能在输入字段中使用%作为值呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-25 16:35:00

最终得到了解决方案,

在查询字符串中添加参数之前,我使用了javascript的encodeURIComponent函数。来自W3Schools

代码语言:javascript
运行
复制
The encodeURI() function is used to encode a URI.
This function encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters).

Tip: Use the decodeURI() function to decode an encoded URI.
票数 1
EN

Stack Overflow用户

发布于 2013-02-21 23:43:42

您正在尝试对已在上一步中进行URL解码的字符串进行URL解码。这就是你的根本原因。

两组已验证和已失效的字符串之间的区别是'&‘字符。不确定为什么带“与”号的验证...解析器可能在到达'%‘之前停止,因为'&’被视为分隔符。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15004452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档