Our next tutorial is about handling user input. We will start with the most common input component which is text field.
Open your index.jsp and add new codes like below,
<%
out.println(“hello world”);
%>
<html>
<head>
<title>SimpleJSP</title>
</head>
<body>
<form>
<input type=”text” name=”username” maxlength=”20″ size=”10″/>
<input type=”submit” value=”Login”/>
</form>
</body>
</html>
Run your jetty and open index.jsp. You will see something like below, one text field with maximum input of 20 character with one Login button.

Right now, if you type anything and press the button it will do nothing. Let’s change our code a little..
<%
String usernameInput = request.getParameter(“username”);
if(null!=usernameInput){
out.println(“hello “+usernameInput);
}else{
out.println(“hello world”);
}
%>
<html>
<head>
<title>SimpleJSP</title>
</head>
<body>
<form>
<input type=”text” name=”username” maxlength=”20″ size=”10″/>
<input type=”submit” value=”Login”/>
</form>
</body>
</html>
Refresh your index.jsp and try type any text in your text field and press Login.. do you see some changing??
What you type will show in the hello text.

You notice that in the latest code, there is one line that capture value from username text field which is request.getParameter(“username”). So, just use this syntax to capture any html input component by changing the parameter input in request.getParameter.
This is the code if we want to have some login page.
<%
String usernameInput = request.getParameter(“username”);
String passwordInput = request.getParameter(“password”);
if(null!=usernameInput && null!=passwordInput ){
out.println(“process user with username=”+usernameInput+” and password = “+passwordInput);
}else{
out.println(“hello world”);
}
%>
<html>
<head>
<title>SimpleJSP</title>
</head>
<body>
<form>
Name:<input type=”text” name=”username” maxlength=”20″ size=”10″/><br/>
Password:<input type=”password” name=”password” maxlength=”20″ size=”10″/><br/>
<input type=”submit” value=”Login”/>
</form>
</body>
</html>
The next tutorial will be connection to database.
Thanks