Difference between revisions of "Java-Business-Application/C2/Servlet-Methods/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
 
{| border =1
 
{| border =1
 
| '''Time'''
 
| '''Time'''
| ''Narration'''
+
| '''Narration'''
  
 
|-
 
|-

Revision as of 16:40, 18 September 2014

Time Narration
00:01 Welcome to the spoken-tutorial on Servlet Methods.
00:06 In this tutorial we will learn to
00:08 create a simple login form using JSP
00:13 Pass parameters using doGet method
00:16 Pass parameters using doPost method
00:20 Difference between doGet and doPost methods
00:25 Here we are using
00:26 Ubuntu Version 12.04
00:30 Netbeans IDE 7.3
00:33 JDK 1.7
00:36 Firefox web-browser 21.0
00:39 You can use any web-browser of your choice.
00:43 To follow this tutorial you must know
00:46 Core Java using Netbeans IDE
00:49 HTML
00:51 Basics of Java Servlets and JSPs
00:56 If not, for relevant tutorials please visit our website.
01:00 We will begin by creating our web application- the Library Management System.
01:06 First, we will create the home page.
01:09 The home page will contain a simple login form.
01:14 It will allow authenticated users to login to the Library Management System.
01:20 Now, let us switch to Netbeans IDE.
01:23 Let us go to the index dot jsp page, that we had already modified earlier.
01:30 I have modified this page to create our home page.
01:35 We keep the title as Home Page.
01:38 Inside the body, we have a table,with border equal to 1.
01:44 You can have a look at the code here.
01:47 Inside the table we have included a heading, Welcome to Library Management System.
01:54 Next, we have paragraph tag that includes, This is the home page for Library Management System.
02:03 Then, we have a hyperlink, which links to a page called visitorHomePage dot jsp.
02:11 We will create this page later.
02:13 Next,we have a very simple login form.
02:18 This form allows a registered user to login .
02:22 Before creating the form you will have to create a servlet named GreetingServlet.
02:28 Pause the tutorial and create a new servlet as explained in the earlier tutorial.
02:35 Note that the servlet name is GreetingServlet.
02:39 The URL pattern should be GreetingServletPath.
02:44 This form has two input elements - Username and Password.
02:50 It also has a Submit button that says Sign In.
02:55 Next, we have a paragraph tag that includes a link to addUser.jsp.
03:03 This is the registration page for those users who have not yet registered.
03:09 Now, let us go to our GreetingServlet.java.
03:14 Note that GreetingServlet.java is created in the same package org.spokentutorial.
03:23 Now, this servlet will be able to access the form data from the request object.
03:30 This servlet will act as a controller.
03:33 Do you recall that we had come across controller earlier?
03:38 Now, we will see what the servlet does as a controller.
03:42 The form data will reside in the request object.
03:46 The first task is to retrieve the form data parameters.
03:51 This is done using the getParameter method on the request object.
03:57 So, let us switch to Netbeans IDE.
04:02 Type inside the doGet method,
04:04 PrintWriter space out equal to response dot getWriter.
04:14 Next, we will retrieve the form data parameters.
04:18 So that on the next line type,
04:20 String space username equal to request dot getParameter within brackets and double quotes userName semicolon.
04:35 Note that this userName is the name we have included in the form tag for User Name.
04:43 Similarly, we will retrieve the password also.
04:48 So on the next line, type, String space password equal to request dot getParameter within brackets and double quotes password semicolon.
05:03 Next, we will print the User Name in the output.
05:08 So, on the next line type
05:10 'out dot println within brackets and double quotes Hello from GET Method plus username.
05:21 Now, to run this project, right-click on MyFirstProject.
05:27 Click on Clean and Build.
05:29 Again right click on MyFirstProject , click on Run.
05:35 So, the server is up and running.
05:38 It has deployed MyFirstProject.
05:41 We have got our home page displayed in the browser.
05:45 Observe that the title of the page is Home Page.
05:50 We can see a very simple login form here.
05:54 Let me enter the Username and Password.
05:58 I will type arya as the Username.
06:02 And arya*123 as the Password.
06.06 Then click on Sign In.
06:09 We can see that we have got the output Hello from GET Method arya.
06:15 Now, the user was able to login here because we have not included any validation inside the code.
06:24 We will do this in the later tutorial.
06:28 Now, have a look at the URL here.
06:31 It is localhost colon 8080 slash MyFirstProject slash GreetingServletPath question mark userName equal to arya and password equal to arya *123.
06:49 Now, form data is separated from the page information by a question mark.
06:56 We can see that username and password that we had entered in the form is inside the URL also.
07:05 Now, let us try to do the same using POST Method.
07:10 So, switch back to the IDE.
07:12 Copy the code we had written for doGet Method and paste in the doPost Method.
07:20 Now, change the println statement to Hello from POST Method.
07:27 Now, let us open index dot jsp.
07:31 Here, we must change the method attribute of the form tag to POST.
07:37 You can have a look at this code now.
07:42 We have form action equal to GreetingServletPath method equal to POST.
07:49 Now, we will run this Project again
07:53 So, Right click on MyFirstProject and click on Run
07:58 We have got an output similar to the one we got, when we used the GET method.
08:04 So let us type User Name and Password again.
08:08 Then click on Sign In.
08:12 Note that we have got Hello from POST Method arya.
08:17 Now, take a look at the URL.
08:19 It is localhost colon 8080 slash MyFirstProject slash GreetingServletPath
08:25 Here we do not see the form data in the URL of the request.
08:30 This is the major difference between doGet and doPost Methods.
08:35 Now, let us learn when to use GET and when to use POST Methods.
08:42 GET Method is used when:
08:44 the form is small and hence the data is less.
08:48 the user wants the contents of the data to be visible in the URL.
08:53 POST Method is used when:
08:55 the form is large and hence the data is more.
09:00 the user does not want the contents of the data to be visible in the URL.
09:06 ex: passwords
09:08 Let us summarize.
09:10 In this tutorial we have learnt to:
09:12 create a simple login form using JSP
09:16 Pass parameters using doGet method
09:19 Pass parameters using doPost method
09:22 Difference between doGet and doPost methods
09:26 Please make sure that you have completed this tutorial before proceeding further.
09:32 Watch the video available at the following link.
09:35 It summarizes the Spoken Tutorial Project
09:38 If you do not have good bandwidth you can download and watch it
09:42 The Spoken Tutorial Project Team
09:45 Conducts workshops using spoken tutorials
09:48 Gives certificates for those who pass an online test
09:52 For more details please write to contact at spoken hyphen tutorial dot org
09:58 Spoken Tutorial Project is a part of the Talk to a Teacher Project
10:02 It is supported by the National Mission on Education through ICT, MHRD, Government of India
10:09 More information on this mission is available at http://spoken-tutorial.org/NMEICT-Intro
10:19 The Library Management System has been contributed by a leading software MNC, through their Corporate Social Responsibility Programme.
10:28 They have also validated the content for this spoken tutorial.
10:32 This is Arya Ratish from IIT Bombay signing off.


Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14