本文介绍了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.

推荐答案

根据:

请注意,可以提交一个空参数 - 这样参数就存在,但没有值。例如,我可以在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