[英]can't read '%' for request.getparameter()
Hi i have a hyperlink from hyperlink i am calling a servlet and also sending a parameter with request but when '%' appended with text then shows null value. 嗨,我有一个来自超链接的超链接,我正在调用servlet,还发送带有请求的参数,但是当'%'附加文本时,则显示空值。
Code Of Jsp Jsp代码
<h1><a href="test11?val=100%">click</a></h1>
Code of servlet servlet代码
String s=request.getParameter("val");
out.print("this is a text"+s);
for <h1><a href="test11?val=100">click</a></h1>
it works fine but when i add '%' it print null. 对于<h1><a href="test11?val=100">click</a></h1>
它可以正常工作,但是当我添加'%'时,它会显示null。
In order to get the % from an URL
you should use it's URLEncoded
version which is %25
. 为了从URL
获取%,您应该使用它的URLEncoded
版本%25
。 So you will end with <h1><a href="test11?val=100%25">click</a></h1>
因此,您将以<h1><a href="test11?val=100%25">click</a></h1>
结尾
%
in an URL
is not just a character, is the the main character for the percent-encoding
used in URLEncoding. URL
%
不仅是字符,还是URLEncoding中使用的percent-encoding
的主要字符。 Other special characters for URLs are ?
URL的其他特殊字符是?
, &
and =
, &
和=
Please try to always encode your URLs, in java please check this link: Java URL encoding of query string parameters in order to do so. 请尝试始终对您的URL进行编码,在Java中,请检查以下链接: 查询字符串参数的Java URL编码 。
Since you are using JSP then try with JSTL to encode the URL. 由于您正在使用JSP,因此请尝试使用JSTL对URL进行编码。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:url value="/test11" var="url">
<c:param name="val" value="100%" />
</c:url>
<a href="${url }">click</a>
Read more about JSP Standard Tag Library 阅读有关JSP标准标记库的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.