The following code tries to determine from which input field the user has filled via the getParameter()
method:
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
System.out.println(request.getParameter("userinput"));
if(request.getParameter("userinput") != "userinput")
accessExampleView(request, response);
else
accessServletSubsidiary(request, response);
}
Visually, I am trying to find out whether the user entered a value in the first field, or the second:
However, each time this runs, it points to accessExampleView
. I tried setting the if
statement logic to:
if(request.getParameter("userinput") != null)
to no avail - the first line continues to be true and routes to the accessExampleView
method.
Essentially, is there a better way to check what kind of value exists in request
object?
Here is the JSP file that this utilizes:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>JSP HTML page</title>
</head>
<body>
<form action="ServletHome" method="post">
<fieldset name="f1">
This page communicates with the servlet page via input types.
<br>
<br>
<label>Enter some text: </label>
<input type="text" name="userinput">
<input type="submit" value="send">
<br>
Enter your age:
<input type="number" name="userAge">
<input type="submit" value="send">
<br>
</fieldset>
</form>
</body>
</html>