What does request.getParameter return?

// index.jsp

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

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

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

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

However I cannot do

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

or

if (one != null) {}

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

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

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.

Leave a Comment