Download Video Source: High-Quality : 15 MB
Click below arrow to download….
Why Forms ?
Forms are the foremost feature found in any web application. I refer form to the HTML "Form" Tag. We do know that we can add Text Box, Buttons, List box to the web page using this Form tag.So to interact with the user, using forms is inevitable. Let's go and see some examples around the web & figure out how important Forms are....
Examples
Yahoo! Mail - Registration PageThis site is world famous & most of us have created an account in Yahoo!
This registration page is built using HTML "Forms" Tag only.
Google - Advanced Search Window
Yet another example of a form...See, if you want to get data from the user, you need a form. Just imagine how it is processed. Let's imagine the steps that follows...
- You will fill the form.
- Then submit the form.
- Then Google server will catch all your inputs.
- It will completely 'change' it's way of search.
- When you search again, you get different results.
HTML Forms
Let’s start with a sample login form. We will have a username & password text box.And finally, we will also add one login button at the bottom of the page.
Here is how the code will look like. Name it, “one.jsp”.
<HTML>HTML Forms & JSP
<FORM ACTION = "two.jsp" METHOD = "POST">
<BR><B>Username : <INPUT TYPE = TEXT NAME = "username">
<BR><B>Password : <INPUT TYPE = TEXT NAME = "password">
<BR><INPUT TYPE = SUBMIT VALUE = "LOGIN">
</FORM>
</HTML>
Now let’s find out what JSP has to do with this. Listen, you designed a page. You got text boxes to type. Think what next. Well, the answer is processing. Once you have your data, you need to process. For example, say once you click on the login button, you have to search the database and validate the login. Whether the user actually has an account & given the right password. Too much theory ? Don’t worry.
HTML can only design the form. It is not having any feature to process data. But JSP can…JSP uses the request attribute to get the form data. So let’s see how actually JSP does it with an example.
The following file is two.jsp
<HTML>
<h3>Form submitted successfully. </h3>
User name : <%=request.getParameter("username").toString()%>
<BR>Password : <%=request.getParameter("password").toString()%>
</HTML>
response Object
Just like the request, we have another object called response. It’s evident from the name that it contains details regarding a page response. One of the famous example used is sendRedirect. This method is used to navigate from one page to another page. Below example will check if the password entered in page one is ‘jothika’.If yes, then it goes to success.jsp. Otherwise, it will go to failed.jsp. Try it…See it for yourselves.
<HTML>
<h3>Form submitted successfully. </h3>
User name : <%=request.getParameter("username").toString()%>
<BR>Password : <%=request.getParameter("password").toString()%>
<%
String username = request.getParameter("username").toString();
String password = request.getParameter("password").toString();
if(password.equals("jothika"))
response.sendRedirect("success.jsp");
else
response.sendRedirect("failed.jsp");
%>
</HTML>
Machi... Super....
ReplyDeleteSuper explanation...
Waiting for more of your uploads on JSP and servlets....
Thanks a lot man.... U have given me a start!!!
@VJ
ReplyDeleteThanks. JSP is over. Now recording Servlets.
Nice one..but isnt this a very insecure application.u can get the password if u know the address of the jsp where the if-else check takes place.but j2ee is meant to be secure one right.
ReplyDelete@Above: Yeah, you are right. Thanks for your comment. For someone, who just starts learning web development, i thought it's first good to learn the navigation flow.
ReplyDeleteLater on, we can take up the security issues, sessions, encryption....
Thanks a Lot . Never Had a friend to teach like this but enjoyed learning your tutorials .Thanks Buddy.
ReplyDeleteA clear view of the servlet & Jsp .... thanks dude.. nice work... awaiting for more uploads. great work keep doing....
ReplyDeleteGo jod dude keeping going. I highly appreciate your attempt to tutor in tamil and your really doing a great job.. our support is always with you dude. expecting lot more releases from you. Thumbs up.
ReplyDeleteThanks a Lot,nice work... awaiting for more uploads. i am expecting lot more releases from you.
ReplyDelete