Difference between revisions of "Java-Business-Application/C2/Java-servlets-and-JSPs/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{|border =1
 
{|border =1
 
| ''' Time '''
 
| ''' Time '''
| '''Narration
+
| '''Narration'''
  
 
|-
 
|-
| 00.01
+
| 00:01
| Welcome to the spoken-tutorial on''' Java Servlets and JSPs.'''
+
| Welcome to the '''spoken-tutorial''' on''' Java Servlets and JSPs.'''
  
 
|-
 
|-
| 00.06
+
| 00:06
| In this tutorial we will learn about:
+
| In this tutorial, we will learn about:
  
 
|-
 
|-
| 00.09
+
|00:09
| '''Web server'''
+
|'''Web server''' ''' Web container'''.
  
 
|-
 
|-
| 00.10
+
| 00:12
| ''' Web container'''
+
| We will also learn to create a simple '''Java Servlet ''' and '''JSP'''.
  
 
|-
 
|-
| 00.12
+
| 00:18
| We will also learn to create a simple '''Java Servlet ''' and '''JSP'''
+
|Here we are using:
  
 
|-
 
|-
| 00.18
+
|00:20
|Here we are using
+
|''' Ubuntu''' Version '''12.04'''
  
 
|-
 
|-
| 00.20
+
|00:23
| ''' Ubuntu Version 12.04'''
+
|''' Netbeans IDE''' 7.3
  
 
|-
 
|-
| 00.23
+
|00:27
| ''' Netbeans IDE 7.3'''
+
|'''JDK''' 1.7
  
 
|-
 
|-
| 00.27
+
|00:29
| '''JDK 1.7'''
+
|'''Firefox''' web-browser 21.0.
  
 
|-
 
|-
| 00.29
+
|00:33
| Firefox web-browser 21.0
+
|You can use any web-browser of your choice.
  
 
|-
 
|-
| 00.33
+
|00:37
| You can use any web-browser of your choice.
+
| To follow this tutorial, you must have knowledge of:
  
 
|-
 
|-
|00.37
+
|00:41
| To follow this tutorial you must have knowledge of
+
|Core Java using '''Netbeans IDE''' and
  
 
|-
 
|-
| 00.41
+
|00:45
| Core Java using '''Netbeans IDE''' and
+
|'''HTML'''.
  
 
|-
 
|-
| 00.45
+
|00:47
| '''HTML'''
+
|If not, for relevant tutorials please visit our website.
  
 
|-
 
|-
| 00.47
+
|00:52
| If not, for relevant tutorials please visit our website.
+
|Before moving onto '''Servlets '''and '''JSP,''' let us first understand a '''web server.'''
  
 
|-
 
|-
| 00.52
+
| 00:58
| Before moving onto '''Servlets '''and '''JSP, '''let us first understand a '''web server.'''
+
| A '''web server '''is a system that delivers content to end-users over the''' Internet.'''
  
 
|-
 
|-
| 00.58
+
| 01:05
|  A '''web server '''is a system that delivers content to end-users over the''' Internet.'''
+
 
+
|-
+
01.05
+
 
|It is also known as '''Internet server'''.
 
|It is also known as '''Internet server'''.
  
 
|-
 
|-
| 01.10
+
| 01:10
| A '''web container''' is a component of the web server that interacts with Java servlets
+
| A '''web container''' is a component of the web server that interacts with '''Java servlets'''.
  
 
|-
 
|-
| 01.18
+
| 01:18
 
|It is also known as '''servlet container.'''
 
|It is also known as '''servlet container.'''
  
 
|-
 
|-
| 01.22
+
| 01:22
|The '''servlet container '''allows the '''servlets '''to execute inside it.
+
|The '''servlet container''' allows the '''servlets '''to execute inside it.
  
 
|-
 
|-
| 01.28
+
| 01:28
 
| Now, let us learn how to write a simple '''servlet.'''
 
| Now, let us learn how to write a simple '''servlet.'''
  
 
|-
 
|-
| 01.32
+
| 01:32
 
|Switch to the '''Netbeans IDE.'''
 
|Switch to the '''Netbeans IDE.'''
 
 
  
 
|-
 
|-
| 01.35
+
| 01:35
| Click on the '''Projects tab '''on the left hand side of the '''IDE.'''
+
| Click on the '''Project''' tab on the left hand side of the '''IDE.'''
  
 
|-
 
|-
| 01.40
+
| 01:40
|Earlier we had created a simple '''Project '''named '''MyFirstProject.'''
+
|Earlier, we had created a simple '''Project '''named '''MyFirstProject.'''
  
 
|-
 
|-
| 01.46
+
| 01:46
|You can see it here on the left hand side of the '''IDE.'''
+
|You can see it here, on the left hand side of the '''IDE.'''
  
 
|-
 
|-
| 01.50
+
| 01:50
| Let us now create a simple '''servlet''' inside this '''project'''.
+
| Let us now create a simple '''servlet''' inside this '''Project'''.
  
 
|-
 
|-
| 01.55
+
| 01:55
| So, right-click on '''MyFirstProject'''.
+
| So, right-click on '''MyFirstProject'''.
 
+
  
 
|-
 
|-
| 01.59
+
| 01:59
| Go to '''New '''and click on '''Servlets.'''
+
| Go to '''New '''and click on '''Servlet.'''
  
 
|-
 
|-
| 02.03
+
| 02:03
| A '''New Servlet '''window opens.
+
| A '''New Servlet '''window opens.
  
 
|-
 
|-
| 02.05
+
| 02:05
| Type the '''Class Name '''as '''MyServlet.'''
+
| Type the '''Class Name '''as '''MyServlet.'''
  
 
|-
 
|-
| 02.09
+
| 02:09
| Type the '''Package Name '''as '''org.spokentutorial'''
+
| Type the '''Package''' name as '''org.spokentutorial'''.
  
 
|-
 
|-
| 02.16
+
| 02:16
| Then click on '''Next.'''
+
| Then click on '''Next.'''
  
 
|-
 
|-
| 02.18
+
| 02:18
| Click on '''Add information to deployment descriptor (web.xml).'''
+
| Click on '''Add information to deployment descriptor (web.xml).'''
  
 
|-
 
|-
| 02.23
+
| 02:23
| We can see that the '''Class Name '''is '''org.spokentutorial.MyServlet.'''
+
| We can see that the '''Class Name''' is '''org.spokentutorial.MyServlet.'''
  
 
|-
 
|-
| 02.30
+
| 02:30
| We can see that '''Servlet Name '''is same as that of the '''Class Name '''which is '''MyServlet.'''
+
| We can see that the '''Servlet Name '''is same as that of the '''Class Name''' which is '''MyServlet.'''
  
 
|-
 
|-
| 02.37
+
| 02:37
| Note that the''' URL pattern ''' is the same name as that of the '''Class Name.''' i.e '''MyServlet'''
+
| Note that the '''URL pattern''' is the same name as that of the '''Class Name.''' i.e '''MyServlet'''.
  
 
|-
 
|-
| 02.45
+
| 02:45
| We can change it to''' MyServletPath. '''
+
| We can change it to''' MyServletPath.'''
  
 
|-
 
|-
| 02.50
+
| 02:50
| Then click on '''Finish.'''
+
| Then click on '''Finish.'''
  
 
|-
 
|-
| 02.53
+
| 02:53
| The source code created by the IDE for '''MyServlet.java''' is seen in the '''Source Editor Window.'''
+
| The '''source code''' created by the IDE for '''MyServlet.java''' is seen in the '''Source Editor window.'''
  
 
|-
 
|-
| 03.01
+
| 03:01
| We see '''MyServlet.java is '''created in the '''package org.spokentutorial.'''
+
| We see '''MyServlet.java''' is created in the '''package org.spokentutorial.'''
  
 
|-
 
|-
| 03.09
+
| 03:09
| Notice that a '''servlet '''is just like any other '''Java class.'''
+
| Notice that the '''servlet '''is just like any other '''Java class'''
  
 
|-
 
|-
| 03.14
+
| 03:14
|Except that a '''servlet '''does not have a '''main method'''.
+
|except that the '''servlet '''does not have a '''main method'''.
  
 
|-
 
|-
| 03.19
+
| 03:19
| Now, let us learn something about '''Glassfish server.'''
+
| Now, let us learn something about '''Glassfish Server.'''
  
 
|-
 
|-
| 03.24
+
| 03:24
 
|A '''servlet''' is deployed in a '''servlet container.'''  
 
|A '''servlet''' is deployed in a '''servlet container.'''  
  
 
|-
 
|-
| 03.28
+
| 03:28
 
|We are using '''Glassfish''' as our '''server.'''
 
|We are using '''Glassfish''' as our '''server.'''
  
 
|-
 
|-
| 03.32
+
| 03:32
|Servlet container is a component of''' Glassfish''' that interacts with servlets.
+
|'''Servlet container''' is a component of''' Glassfish''' that interacts with servlets.
  
 
|-
 
|-
| 03.39
+
|03:39
| Now, let us come back to '''Netbeans IDE.'''
+
|Now, let us come back to '''Netbeans IDE.'''
  
 
|-
 
|-
| 03.42
+
| 03:42
| Note that MyServlet extends the '''HttpServlet. '''
+
| Note that '''MyServlet''' extends the '''HttpServlet.'''
  
 
|-
 
|-
| 03.48
+
| 03:48
| At the bottom of the code, we can see '''HttpServlet methods.'''
+
| At the bottom of the code, we can see '''HttpServlet methods.'''
  
 
|-
 
|-
| 03.54
+
| 03:54
| Click on the''' plus sign''''' on the left, to view these '''methods'''.
+
| Click on the '''plus''' sign on the left to view these '''methods'''.
  
 
|-
 
|-
| 03.59
+
| 03:59
| We see the methods -''' doGet''', '''doPost''' and '''getServletInfo''' methods.
+
| We see the '''method'''s - '''doGet''', '''doPost''' and '''getServletInfo''' '''method'''s.
  
 
|-
 
|-
| 04.09
+
| 04:09
|We can override these methods.
+
|We can '''override''' these '''method'''s.
  
 
|-
 
|-
| 04.12
+
|04:12
| We can see that there is one more method named '''processRequest '''at the top.
+
|We can see that there is one more '''method''' named '''processRequest '''at the top.
  
 
|-
 
|-
| 04.18
+
| 04:18
| We will delete '''processRequest '''and '''getServletInfo''' methods to avoid confusion.
+
| We will delete '''processRequest '''and '''getServletInfo''' methods to avoid confusion.
  
 
|-
 
|-
| 04.25
+
| 04:25
| So we are left with two methods '''doGet''' and '''doPost.'''
+
| So, we are left with two methods '''doGet''' and '''doPost.'''
  
 
|-
 
|-
| 04.31
+
| 04:31
| For now, we will look at the '''doGet method.'''
+
| For now, we will look at the '''doGet method.'''
  
 
|-
 
|-
|04.35
+
|04:35
| '''doGet'''is the default '''method''' for any simple '''URL'''request.
+
| '''doGet''' is the default '''method''' for any simple '''URL'''request.
  
 
|-
 
|-
| 04.41
+
| 04:41
| So we will type some code inside the '''doGet method.'''
+
| So, we will type some code inside the '''doGet method.'''
  
 
|-
 
|-
| 04.45
+
| 04:45
| We had already deleted '''processRequest method.'''
+
| We had already deleted '''processRequest method.'''
  
 
|-
 
|-
| 04.49
+
| 04:49
|So, remove the method call for '''processRequest method.'''
+
| So, remove the '''method call''' for '''processRequest''' '''method.'''
  
 
|-
 
|-
| 04.54
+
| 04:54
 
|Also remove it from the '''doPost method.'''
 
|Also remove it from the '''doPost method.'''
  
 
|-
 
|-
| 04.58
+
| 04:58
| Now, let us come to the '''doGet method'''
+
| Now, let us come to the '''doGet method'''
  
 
|-
 
|-
| 05.01
+
| 05:01
 
|We can see that there are two '''parameters''' that are passed to the '''doGet method.'''
 
|We can see that there are two '''parameters''' that are passed to the '''doGet method.'''
  
 
|-
 
|-
| 05.07
+
| 05:07
| One is the '''request '''and the other is the '''response object.'''
+
| One is the '''request '''and the other is the '''response object.'''
  
 
|-
 
|-
| 05.12
+
| 05:12
| Also notice that, '''request '''is of type '''HttpServletRequest.'''
+
| Also notice that '''request '''is of type '''HttpServletRequest.'''
  
 
|-
 
|-
| 05.18
+
| 05:18
| And '''response object '''is of  type '''HttpServletResponse.'''
+
| And '''response object '''is of  type '''HttpServletResponse.'''
  
 
|-
 
|-
| 05.22
+
| 05:22
| We will use the '''response object '''to send the '''HTML response '''back to the '''client''' side.
+
| We will use the '''response object''' to send the '''HTML response''' back to the '''client''' side.
  
 
|-
 
|-
| 05.30
+
| 05:30
| For that, we will have to create a '''PrintWriter object.'''
+
| For that, we will have to create a '''PrintWriter object.'''
  
 
|-
 
|-
|  05.35
+
|  05:35
|  Notice that the '''PrintWriter class '''is already imported.
+
|  Notice that the '''PrintWriter class''' is already imported.
  
 
|-
 
|-
|  05.40
+
|  05:40
|  So, inside the '''doGet method'''type '''PrintWriter ''space ''writer ''equal to ''response ''dot ''getWriter ''open and close brackets semicolon'''''
+
|  So, inside the '''doGet method''' type: '''PrintWriter''' space '''writer''' equal to '''response''' dot '''getWriter''' open and close brackets '''semicolon'''.
  
 
|-
 
|-
| 05.57
+
| 05:57
 
|Press '''Enter.'''
 
|Press '''Enter.'''
  
 
|-
 
|-
| 05.59
+
| 05:59
| On the next line type -
+
| On the next line, type:
  
 
|-
 
|-
|  06.02
+
|  06:02
|'''writer ''dot ''println ''within brackets and double quotes ''welcome.'''
+
|'''writer '''dot '''println '''within brackets and double quotes '''Welcome.'''
  
 
|-
 
|-
|06.09
+
|06:09
| Then, Press '''Ctrl S ''' to save the file.
+
| Then, press '''Ctrl S''' to '''save''' the file.
  
 
|-
 
|-
| 06.14
+
| 06:14
| Now, let us run the '''servlet.'''
+
| Now, let us '''run''' the '''servlet.'''
  
 
|-
 
|-
| 06.17
+
| 06:17
| So on the left hand side, in the '''Projects tab '''right click on '''MyServlet''''' dot '''''java'''.
+
| So, on the left hand side, in the '''Projects tab '''right click on '''MyServlet''' dot '''java'''.
  
 
|-
 
|-
| 06.24
+
| 06:24
| Then, Click on '''Run File.'''
+
| Then, click on '''Run File.'''
  
 
|-
 
|-
|   06.27
+
|06:27
 
|We get a '''Set Servlet Execution URI '''dialog box.
 
|We get a '''Set Servlet Execution URI '''dialog box.
  
 
|-
 
|-
| 06.32
+
| 06:32
 
|Click on '''OK.'''
 
|Click on '''OK.'''
  
 
|-
 
|-
| 06.35
+
| 06:35
| When the browser window opens, look at the URL.
+
| When the browser '''window''' opens, look at the URL.
  
 
|-
 
|-
| 06.39
+
| 06:39
| It is''' localhost ''colon'' 8080 ''slash'' MyFirstProject slash MyServletPath.'''
+
| It is''' localhost''' ''colon'' '''8080''' ''slash'' '''MyFirstProject''' ''slash'' '''MyServletPath.'''
  
 
|-
 
|-
| 06.47
+
| 06:47
| Here '''MyFirstProject '''is the '''context name '''and '''MyServletPath '''is the '''URL Pattern '''that we had set.
+
| Here, '''MyFirstProject '''is the '''context name '''and '''MyServletPath '''is the '''URL pattern''' that we had set.
  
 
|-
 
|-
| 06.55
+
| 06:55
| We see the text '''welcome '''printed on the browser.
+
| We can see the text '''Welcome '''printed on the browser.
  
 
|-
 
|-
| 07.00
+
| 07:00
| Now go back to the '''netbeans IDE.'''
+
| Now go back to the '''Netbeans IDE.'''
  
 
|-
 
|-
| 07.03
+
| 07:03
| In the '''println''' method we can pass '''html''' code.
+
| In the '''println''' '''method''', we can pass '''html''' code.
  
 
|-
 
|-
| 07.07
+
| 07:07
| For example, put welcome in '''h3 tag.'''
+
| For example, put '''Welcome''' in '''h3 tag.'''
  
 
|-
 
|-
| 07.12
+
| 07:12
| Now,'''Save''' the file.
+
| Now, '''save''' the file.
  
 
|-
 
|-
| 07.14
+
| 07:14
| Since we deployed this servlet earlier, we need not run it again.  
+
| Since we deployed this servlet earlier, we need not '''run''' it again.  
 
+
  
 
|-
 
|-
| 07.20
+
| 07:20
 
|'''The web container '''automatically detects it.
 
|'''The web container '''automatically detects it.
  
 
|-
 
|-
| 07.23
+
| 07:23
| So, we can go back to the '''browser'''.
+
| So, we can go back to the '''browser'''.
 
+
|-
+
|  07.27
+
|  Refresh.
+
 
+
  
 
|-
 
|-
| 07.28
+
| 07:27
| We see the message '''Welcome''' in a different format.
+
| Refresh.We see the message '''Welcome''' in a different format.
  
 
|-
 
|-
|  07.32
+
|  07:32
 
|  Now, come back to the '''IDE'''.
 
|  Now, come back to the '''IDE'''.
  
 
|-
 
|-
|  07.35
+
|  07:35
 
|  Thus, we have successfully created a '''servlet.'''
 
|  Thus, we have successfully created a '''servlet.'''
  
 
|-
 
|-
|  07.39
+
|  07:39
|  We can create any web application using '''servlets.'''
+
|  We can create any '''web application''' using '''servlets.'''
  
 
|-
 
|-
|  07.45
+
|  07:45
 
|  We used the servlet to display an '''HTML code.'''
 
|  We used the servlet to display an '''HTML code.'''
  
 
|-
 
|-
| 07.49
+
| 07:49
| Notice that, we have '''HTML '''code inside the '''Java code.'''
+
| Notice that we have '''HTML''' code inside the '''Java code.'''
  
 
|-
 
|-
| 07.54
+
| 07:54
| Even though this is possible, it is difficult to do for large web applications.
+
| Even though this is possible, it is difficult to do for large '''web applications'''.
  
 
|-
 
|-
| 08.00
+
| 08:00
 
|And hence not a recommended practice.
 
|And hence not a recommended practice.
  
 
|-
 
|-
| 08.03
+
| 08:03
| It would be better to replace this using '''JSP (Java Server Pages.)'''
+
| It would be better to replace this using '''JSP''' or '''Java Server Pages.'''
  
 
|-
 
|-
| 08.10
+
| 08:10
| We will see the use of '''servlets '''and '''jsps.'''
+
| We will see the use of '''servlets '''and '''JSPs.'''
  
 
|-
 
|-
| 08.13
+
| 08:13
 
| '''Servlets '''and '''JSPs '''are used together to separate presentation from content.
 
| '''Servlets '''and '''JSPs '''are used together to separate presentation from content.
  
 
|-
 
|-
| 08.20
+
| 08:20
| '''Servlets '''act as the '''controller '''and '''JSPs '''act as the '''view '''
+
| '''Servlets '''act as the '''controller '''and '''JSPs '''act as the '''view '''.
  
 
|-
 
|-
| 08.25
+
| 08:25
| '''Servlets '''contain '''HTML code ''' inside '''Java code.'''
+
| '''Servlets''' contain '''HTML code''' inside '''Java code.'''
  
 
|-
 
|-
| 08.30
+
| 08:30
| '''JSPs '''contain '''Java code ''' inside '''HTML code.'''
+
| '''JSPs''' contain '''Java code''' inside '''HTML code.'''
  
 
|-
 
|-
| 08.35
+
| 08:35
 
|We will learn more about these in the coming tutorials.
 
|We will learn more about these in the coming tutorials.
  
 
|-
 
|-
|08.39
+
|08:39
| Now, Switch back to '''Netbeans IDE.'''     
+
| Now, switch back to '''Netbeans IDE.'''     
  
 
|-
 
|-
| 08.42
+
| 08:42
 
|We will now create a simple '''JSP page.'''
 
|We will now create a simple '''JSP page.'''
  
 
|-
 
|-
| 08.47
+
| 08:47
| So, Right click on '''MyFirstProject'''.  
+
| So, right click on '''MyFirstProject'''.  
 
+
|-
+
| 08.50
+
|  Go to '''New.'''
+
  
 
|-
 
|-
| 08.51
+
| 08:50
|  and click on '''JSP. '''
+
Go to '''New''' and click on '''JSP.'''
  
 
|-
 
|-
| 08.54
+
| 08:54
| A new '''JSP window '''opens.
+
| A '''New JSP''' window opens.
  
 
|-
 
|-
| 08.57
+
| 08:57
| Type the filename as welcome .
+
| Type the '''Filename''' as '''welcome'''.
  
 
|-
 
|-
| 09.01
+
| 09:01
| And then click on '''Finish.'''
+
| And then click on '''Finish.'''
  
 
|-
 
|-
| 09.04
+
| 09:04
| Click on the '''Projects tab '''on the left hand side  
+
| Click on the '''Projects tab ''' on the left hand side.
  
 
|-
 
|-
| 09.07
+
| 09:07
| We can see that '''Welcome.jsp '''is under '''Web Pages '''folder.
+
| We can see that '''Welcome.jsp '''is under '''Web Pages '''folder.
  
 
|-
 
|-
| 09.13
+
| 09:13
| Now, In the editor, change '''Hello World''' to '''Welcome'''.
+
| Now, in the editor, change '''Hello World''' to '''Welcome'''.
  
 
|-
 
|-
| 09.19
+
| 09:19
|Notice that '''Welcome '''is within '''h1 tags.'''
+
|Notice that '''Welcome '''is within ''' "h1" tags.'''
  
 
|-
 
|-
| 09.23
+
| 09:23
|Now, '''Save''' the file.
+
|Now, '''save''' the file.
  
 
|-
 
|-
|09.25
+
|09:25
 
|Come back to the '''browser.'''
 
|Come back to the '''browser.'''
  
 
|-
 
|-
| 09.27
+
| 09:27
| In the url after '''MyFirstProject''' '''''slash''''' type '''welcome.jsp'''
+
| In the url, after '''MyFirstProject''' slash, type: '''welcome.jsp'''.
  
 
|-
 
|-
| 09.35
+
| 09:35
| We see the output '''Welcome.'''
+
| We see the output '''Welcome.'''
  
 
|-
 
|-
| 09.38
+
| 09:38
| Therefore for presentation purpose '''jsp '''is preferred.  
+
| Therefore, for presentation purpose '''JSP '''is preferred.  
  
 
|-
 
|-
| 09.42
+
| 09:42
| Let us summarize
+
| Let us summarize.
  
 
|-
 
|-
| 09.44
+
| 09:44
|In this tutorial we have learnt
+
|In this tutorial, we have learnt:
  
 
|-
 
|-
| 09.47
+
| 09:47
| About web server and web container
+
|About '''web server''' and '''web container'''.
  
 
|-
 
|-
| 09.49
+
| 09:49
| To create a simple servlet
+
|To create a simple '''servlet'''.
  
 
|-
 
|-
| 09.52
+
| 09:52
| To create a simple jsp
+
|To create a simple '''JSP'''.
  
 
|-
 
|-
| 09.55
+
| 09:55
 
| Please make sure that you have completed this tutorial before proceeding further.
 
| Please make sure that you have completed this tutorial before proceeding further.
  
 
|-
 
|-
| 10.01
+
| 10:01
| Watch the video available at the following link
+
| Watch the video available at the following link.
  
 
|-
 
|-
| 10.04
+
| 10:04
| It summarizes the Spoken Tutorial project
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
| 10.08
+
| 10:08
| If you do not have good bandwidth, you can download and watch it
+
| If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
|10.13
+
|10:13
| The Spoken Tutorial Project Team
+
|The Spoken Tutorial Project Team:
  
 
|-
 
|-
| 10.15
+
| 10:15
| Conducts workshops using spoken tutorials
+
|Conducts workshops using spoken tutorials.
  
 
|-
 
|-
| 10.19
+
| 10:19
| Gives certificates for those who pass an online test
+
|Gives certificates to those who pass an online test.
  
 
|-
 
|-
| 10.22
+
| 10:22
| For more details, please write to contact at spoken hyphen tutorial dot org
+
|For more details, please write to: contact at spoken hyphen tutorial dot org.
  
 
|-
 
|-
| 10.28
+
| 10:28
|  Spoken Tutorial Project is a part of the Talk to a Teacher project
+
|  Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
  
 
|-
 
|-
| 10.32
+
| 10:32
| It is supported by the National Mission on Education through ICT, MHRD, Government of India
+
| It is supported by the National Mission on Education through ICT, MHRD, Government of India.
  
 
|-
 
|-
| 10.40
+
| 10:40
| More information on this Mission is available at  http://spoken-tutorial.org/NMEICT- Intro
+
| More information on this mission is available at  http://spoken-tutorial.org/NMEICT- Intro .
  
 
|-
 
|-
| 10.50
+
| 10:50
|  The Library Management System has been contributed by a leading software MNC, through their Corporate Social Responsibility program
+
|  The '''Library Management System''' has been contributed by a leading '''software MNC''' through their "Corporate Social Responsibility" program.
  
 
|-
 
|-
| 11.00
+
| 11:00
 
|They have also validated the content for this spoken tutorial.
 
|They have also validated the content for this spoken tutorial.
  
 
|-
 
|-
| 11.04
+
| 11:04
|This is Arya Ratish from IIT Bombay signing off.
+
|This is Arya Ratish from IIT Bombay, signing off.
 
Thank you for joining.
 
Thank you for joining.
  
 
|}
 
|}

Latest revision as of 16:44, 9 March 2017

Time Narration
00:01 Welcome to the spoken-tutorial on Java Servlets and JSPs.
00:06 In this tutorial, we will learn about:
00:09 Web server Web container.
00:12 We will also learn to create a simple Java Servlet and JSP.
00:18 Here we are using:
00:20 Ubuntu Version 12.04
00:23 Netbeans IDE 7.3
00:27 JDK 1.7
00:29 Firefox web-browser 21.0.
00:33 You can use any web-browser of your choice.
00:37 To follow this tutorial, you must have knowledge of:
00:41 Core Java using Netbeans IDE and
00:45 HTML.
00:47 If not, for relevant tutorials please visit our website.
00:52 Before moving onto Servlets and JSP, let us first understand a web server.
00:58 A web server is a system that delivers content to end-users over the Internet.
01:05 It is also known as Internet server.
01:10 A web container is a component of the web server that interacts with Java servlets.
01:18 It is also known as servlet container.
01:22 The servlet container allows the servlets to execute inside it.
01:28 Now, let us learn how to write a simple servlet.
01:32 Switch to the Netbeans IDE.
01:35 Click on the Project tab on the left hand side of the IDE.
01:40 Earlier, we had created a simple Project named MyFirstProject.
01:46 You can see it here, on the left hand side of the IDE.
01:50 Let us now create a simple servlet inside this Project.
01:55 So, right-click on MyFirstProject.
01:59 Go to New and click on Servlet.
02:03 A New Servlet window opens.
02:05 Type the Class Name as MyServlet.
02:09 Type the Package name as org.spokentutorial.
02:16 Then click on Next.
02:18 Click on Add information to deployment descriptor (web.xml).
02:23 We can see that the Class Name is org.spokentutorial.MyServlet.
02:30 We can see that the Servlet Name is same as that of the Class Name which is MyServlet.
02:37 Note that the URL pattern is the same name as that of the Class Name. i.e MyServlet.
02:45 We can change it to MyServletPath.
02:50 Then click on Finish.
02:53 The source code created by the IDE for MyServlet.java is seen in the Source Editor window.
03:01 We see MyServlet.java is created in the package org.spokentutorial.
03:09 Notice that the servlet is just like any other Java class
03:14 except that the servlet does not have a main method.
03:19 Now, let us learn something about Glassfish Server.
03:24 A servlet is deployed in a servlet container.
03:28 We are using Glassfish as our server.
03:32 Servlet container is a component of Glassfish that interacts with servlets.
03:39 Now, let us come back to Netbeans IDE.
03:42 Note that MyServlet extends the HttpServlet.
03:48 At the bottom of the code, we can see HttpServlet methods.
03:54 Click on the plus sign on the left to view these methods.
03:59 We see the methods - doGet, doPost and getServletInfo methods.
04:09 We can override these methods.
04:12 We can see that there is one more method named processRequest at the top.
04:18 We will delete processRequest and getServletInfo methods to avoid confusion.
04:25 So, we are left with two methods doGet and doPost.
04:31 For now, we will look at the doGet method.
04:35 doGet is the default method for any simple URLrequest.
04:41 So, we will type some code inside the doGet method.
04:45 We had already deleted processRequest method.
04:49 So, remove the method call for processRequest method.
04:54 Also remove it from the doPost method.
04:58 Now, let us come to the doGet method
05:01 We can see that there are two parameters that are passed to the doGet method.
05:07 One is the request and the other is the response object.
05:12 Also notice that request is of type HttpServletRequest.
05:18 And response object is of type HttpServletResponse.
05:22 We will use the response object to send the HTML response back to the client side.
05:30 For that, we will have to create a PrintWriter object.
05:35 Notice that the PrintWriter class is already imported.
05:40 So, inside the doGet method type: PrintWriter space writer equal to response dot getWriter open and close brackets semicolon.
05:57 Press Enter.
05:59 On the next line, type:
06:02 writer dot println within brackets and double quotes Welcome.
06:09 Then, press Ctrl S to save the file.
06:14 Now, let us run the servlet.
06:17 So, on the left hand side, in the Projects tab right click on MyServlet dot java.
06:24 Then, click on Run File.
06:27 We get a Set Servlet Execution URI dialog box.
06:32 Click on OK.
06:35 When the browser window opens, look at the URL.
06:39 It is localhost colon 8080 slash MyFirstProject slash MyServletPath.
06:47 Here, MyFirstProject is the context name and MyServletPath is the URL pattern that we had set.
06:55 We can see the text Welcome printed on the browser.
07:00 Now go back to the Netbeans IDE.
07:03 In the println method, we can pass html code.
07:07 For example, put Welcome in h3 tag.
07:12 Now, save the file.
07:14 Since we deployed this servlet earlier, we need not run it again.
07:20 The web container automatically detects it.
07:23 So, we can go back to the browser.
07:27 Refresh.We see the message Welcome in a different format.
07:32 Now, come back to the IDE.
07:35 Thus, we have successfully created a servlet.
07:39 We can create any web application using servlets.
07:45 We used the servlet to display an HTML code.
07:49 Notice that we have HTML code inside the Java code.
07:54 Even though this is possible, it is difficult to do for large web applications.
08:00 And hence not a recommended practice.
08:03 It would be better to replace this using JSP or Java Server Pages.
08:10 We will see the use of servlets and JSPs.
08:13 Servlets and JSPs are used together to separate presentation from content.
08:20 Servlets act as the controller and JSPs act as the view .
08:25 Servlets contain HTML code inside Java code.
08:30 JSPs contain Java code inside HTML code.
08:35 We will learn more about these in the coming tutorials.
08:39 Now, switch back to Netbeans IDE.
08:42 We will now create a simple JSP page.
08:47 So, right click on MyFirstProject.
08:50 Go to New and click on JSP.
08:54 A New JSP window opens.
08:57 Type the Filename as welcome.
09:01 And then click on Finish.
09:04 Click on the Projects tab on the left hand side.
09:07 We can see that Welcome.jsp is under Web Pages folder.
09:13 Now, in the editor, change Hello World to Welcome.
09:19 Notice that Welcome is within "h1" tags.
09:23 Now, save the file.
09:25 Come back to the browser.
09:27 In the url, after MyFirstProject slash, type: welcome.jsp.
09:35 We see the output Welcome.
09:38 Therefore, for presentation purpose JSP is preferred.
09:42 Let us summarize.
09:44 In this tutorial, we have learnt:
09:47 About web server and web container.
09:49 To create a simple servlet.
09:52 To create a simple JSP.
09:55 Please make sure that you have completed this tutorial before proceeding further.
10:01 Watch the video available at the following link.
10:04 It summarizes the Spoken Tutorial project.
10:08 If you do not have good bandwidth, you can download and watch it.
10:13 The Spoken Tutorial Project Team:
10:15 Conducts workshops using spoken tutorials.
10:19 Gives certificates to those who pass an online test.
10:22 For more details, please write to: contact at spoken hyphen tutorial dot org.
10:28 Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
10:32 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
10:40 More information on this mission is available at http://spoken-tutorial.org/NMEICT- Intro .
10:50 The Library Management System has been contributed by a leading software MNC through their "Corporate Social Responsibility" program.
11:00 They have also validated the content for this spoken tutorial.
11:04 This is Arya Ratish from IIT Bombay, signing off.

Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14