本文介绍了request.getParameter 返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

//index.jsp

// index.jsp

<form method="post" action="backend.jsp">
<input type="text" name="one" />
<input type="submit value="Submit" />
</form>

在 backend.jsp 中 request.getParameter("one");回来了?

In backend.jsp what does request.getParameter("one"); return?

request.getParameter("one").getClass().getName();

返回java.lang.String,所以它一定是一个String吧?

returns java.lang.String, so it must be a String right?

但是我做不到

String one = request.getParameter("one");
if (!"".equals(one)) {}

if (one != null) {}

这是显而易见的,因为变量一不返回空值.是

This is obvious, because variable one does not return null. Is

if (one.length() > 0) {}

唯一的办法,还是有更好的解决方案或更好的方法?我正在考虑将这两种解决方案都放在 jsp 上.在这种情况下,使用 servlet(虽然 jsp 是 servlet)是一个不同的用例.

only way to go, or are there better solutions or a better approach? I am considering both solutions to be on jsp. Using a servlet (although jsp is a servlet) is a different use case in this scenario.

推荐答案

根据 Javadoc:

以字符串形式返回请求参数的值,如果参数不存在.

请注意,可以提交一个空参数 - 这样参数存在,但没有值.例如,我可以在 URL 中包含 &log=&somethingElse 以启用日志记录,而无需指定 &log=true.在这种情况下,该值将是一个空字符串 ("").

Do note that it is possible to submit an empty parameter - such that the parameter exists, but has no value. For example, I could include &log=&somethingElse into the URL to enable logging, without needing to specify &log=true. In this case, the value will be an empty String ("").

这篇关于request.getParameter 返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 01:13