request.getParameter返回什么? [英] What does request.getParameter return?

查看:167
本文介绍了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); return?

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

request.getParameter(一个)。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) {}

这很明显,因为变量1不会返回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


以String形式返回请求参数的值,如果
参数不存在,则返回null。

Returns the value of a request parameter as a String, or null if the parameter does not exist.

请注意,可以提交一个空参数 - 这样参数就存在,但没有值。例如,我可以在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返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆