SlideShare a Scribd company logo
Tutorial:  Server-Side Web Applications with Java, JSP and Tomcat Eran Toch December 2004 Methodologies in Information Systems Development
Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The  Phones  Web Application Writing JavaBeans  Writing JSPs Includes, session and application Model 2 Architecture
Web Application vs. Web Site Web Site Web Application
The Difference – cont’d Web sites are Static File based May include client’s JavaScript code Web Applications are Dynamic (output depend on input) Database based Multi-layered Session dependent (most of the times) Personalized (some of the times)
Java Web Application Architecture JSP Application Server Browser Servlet Java Classes / EJB HTTP / HTML DB / ERP /  Legacy
Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The  Phones  Web Application Writing JavaBeans  Writing JSPs Includes, session and application Model 2 Architecture
Tomcat Installation Go to:  http://jakarta.apache.org/tomcat/ Download the latest version (currently 5.5.4) by going to: Downloads -> Binaries -> Tomcat 5.5.4.  For Windows, download the  exe  version – with a Windows setup. The direct link:  http://apache.fresh.co.il/jakarta/tomcat-5/v5.5.4/bin/jakarta-tomcat-5.5.4.exe   For Linux, read the setup manual: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/setup.html
Tomcat and Java 5 Please note that Tomcat v. 5.5.4 requires J2SE 1.5 (also known as J2SE 5) or above.  If you want to use J2SE 1.4, download Tomcat 5.0.+
Tomcat Installation – cont’d If you want Tomcat to startup every time the computer is rebooted, check the “service” option. If you wish to use Tomcat for only for development, it’s best to leave the service option unchecked.
Tomcat Installation - Port You can configure the port that Tomcat will be using. If you want it to be available publicly (behind firewalls etc), change the default port to 80. Otherwise, leave it as it is (880). You can always change it later, in the [TOMCAT_HOME]/conf/server.xml configuration file.
Running Tomcat Start Tomcat by running Tomcat monitor (Start Menu -> Apache Tomcat -> Monitor Tomcat), and click on Start.  Point your browser to:  http://localhost:8080 . If Tomcat works, you should see something like this If not, check out the logs (C:\[TOMCAT_HOME]\logs\stdout) and see what went wrong.
Managing Tomcat Go to the management console by clicking on the “management” link in the Tomcat root homepage, or directly by going to:  http :// localhost : 8080 / manager / html .  The default username is “admin”, and the default password is ”” You can change it by changing the [TOMCAT_HOME]\conf\tomcat-users.xml.
Managing Tomcat Console Web Application management  Number of current sessions Start, stop, restart and un-deploy applications
Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The  Phones  Web Application Writing JavaBeans  Writing JSPs Includes, session and application Model 2 Architecture
Building A Web Application Build the following folder structure under [TOMCAT-HOME]\webapps Tomcat-home conf common webapps ... phones WEB-INF lib classes jsp This is the hard way… There are better
Creating JSP Project in Eclipse Open a project for the JSP pages Choose the type “Simple project”
Creating JSP Project – cont’d Choose the path to the jsp folder Click “Finish”
Creating Java Classes Project Create a new project Choose “Java Project”
Creating Java Project – cont’d Choose the path to the WEB-INF/classes folder
Creating Java Project – cont’d Make sure the output build path is in the WEB-INF classes folder Necessary libraries could be added now
Better ways Download MyEclipse IDE extension from: http://www.myeclipseide.com/ Download Lomboz plugin for Eclipse at:  http://www.objectlearn.com/index.jsp Both of these plugins will give you: Easier deployment of projects JSP debugging JSP error detection (important!)
Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The  Phones  Web Application Writing JavaBeans  Writing JSPs Includes, session and application Model 2 Architecture
Our “Phones” Application Simple application that displays phone records from the database (stupid, shameless)  Architecture: select_entry.jsp display_phone.jsp PhoneEntry.java DBConnector.java Database
PhoneEntry.java package edu.technion.methodologies.phones ;   public class PhoneEntry  { private int id = 0 ; private String name ; private  String phone ; private  String email ; public void load(int id ) { DBConnector.loadPhone(id, this ); } public void save () { if (id == 0 ) { id = DBConnector.insertPhone(this ); } else { DBConnector.updatePhone(id, this ); } } //getters and setters… }
DBConnector.java See the advanced Java tutorial…
Writing Scriplets in JSP Write HTML as normal Dynamic parts between <%  %>  Eg <HTML> <BODY> Hello!  The time is now <%= new java.util.Date() %>  </BODY>  </HTML>
JSP Scripting Elements Expressions   <%=  expression  %>   evaluated and inserted into the output  Scriptlets   <%  code  %>   inserted into the servlet's  service  method  Declarations   <%!  code  %>  inserted into the body of the servlet class, outside of any existing methods
JSP Directives There are two main types of directive:  page   lets you do things like import classes, customize the servlet superclass etc Include lets you insert a file into the servlet class at the time the JSP file is translated into a servlet. <%@  directive attribute=&quot;value&quot;  %>
select_entry.jsp <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <HTML> <HEAD> <TITLE> Phones Application </TITLE> </HEAD> <BODY> <form  action = &quot;display_phone.jsp&quot;   method = &quot;post&quot; > <table  border = 0 > <tr> <td> ID:  </td> <td><input  type = &quot;text&quot;   name = &quot;id&quot; ></td> </tr> <tr> <td> &nbsp; </td> <td><input  type = &quot;submit&quot; ></td> </tr> </table>   </form> </BODY> </HTML> HTML Header HTML form Nested HTML table structure HTML text input
select_entry.jsp – the HTML output
display_phone.jsp <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <%@ page   import = &quot;edu.technion.methodologies.phones.*&quot;  %> <HTML> <HEAD> <TITLE> Phone Entry </TITLE> </HEAD> <BODY> <% String idParam = request.getParameter( &quot;id&quot; ); int  id = 0; if  (idParam !=  null ){ id = Integer.parseInt(idParam); } PhoneEntry phoneEntry =  new  PhoneEntry(); phoneEntry.load(id); %> Handling the request Creating the JavaBean Importing libraries
display_phone.jsp – cont’d <table  border = 0 > <tr> <td> Name: </td> <td><b> <%= phoneEntry.getName() %> </b></td> </tr> <tr> <td> Phone: </td> <td> <%= phoneEntry.getPhone() %> </td> </tr> <tr> <td> Email: </td> <td> <%= phoneEntry.getEmail() %> </td> </tr> </table>   </BODY> </HTML>
display_phone.jsp – the HTML Output
Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The  Phones  Web Application Writing JavaBeans  Writing JSPs Includes, session and application Model 2 Architecture
JSP Include Inserting elements into the JSP page in complication time <table  border = &quot;0&quot;   width = &quot;100%&quot;   cellpadding = &quot;4&quot; > <tr  bgcolor = &quot;99CCFF&quot; > <td><a  href = &quot;select_entry.jsp&quot; > home </a></td> </tr> </table> Included JSP file
JSP Include – cont’d … <BODY> <%@ include   file = &quot;header.jsp&quot; %> <% … We add the include declarative into display_phone.jsp  And we get:
Session and Application Objects A session is an object associated with a visitor.   Data can be put in the session and retrieved from it  Sessions are timed-out – the default is ~25 minutes The application object is accessed similarly, but is unique and global for the web application //Setting an object within the session session.setAttribute( &quot;last_searched_id&quot; ,  new  Integer(id)); //Getting an object from the session Integer lastID = (Integer)session.getAttribute( &quot;last_searched_id&quot; ); out.println(lastID);
Advanced Issues Servlets – have many advantages over JSP Inheritance Class structure Tag libraries Enterprise Java Beans J2EE Frameworks (WebLogic, Web Sphere, JBoss)
Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The  Phones  Web Application Writing JavaBeans  Writing JSPs Includes, session and application Model 2 Architecture
Model 2 Architecture recommended approach for designing medium- and large-sized Web applications  An implementation of the  Model-View-Controller (MVC) pattern Applications have 3 layers Model :  containing all data and operations  JSP classes or beans   View :  creating various presentations  JSP – focus on static data Controller :  receiving requests, updating the model, and delegating to views  servlet
Model 2 Architecture – cont’d .jsp .jsp Form request forward Database classes servlet VIEW CONTROLLER MODEL
Struts Struts is an open source framework created within the Jakarta project by the Apache Software Foundation Supports Model-View-Controller (MVC) design pattern http://struts.apache.org/
References Core Servlets and JavaServer Pages, Vol. 1: Core Technologies, Second Edition, by Marty Hall, Larry Brown Sun’s JSP Tutorial: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html JavaBeans Tutorial: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPBeans.html A set of advanced (and untidy) tutorials: http://www.coreservlets.com/

More Related Content

PPT
Web Applications and Deployment
PPT
Data Access with JDBC
PPT
Unified Expression Language
PPT
JSF 2 and beyond: Keeping progress coming
PPT
Automated Testing Of Web Applications Using XML
PPT
Adobe Flex4
PPT
Jsf2.0 -4
PDF
I pad uicatalog_lesson02
Web Applications and Deployment
Data Access with JDBC
Unified Expression Language
JSF 2 and beyond: Keeping progress coming
Automated Testing Of Web Applications Using XML
Adobe Flex4
Jsf2.0 -4
I pad uicatalog_lesson02

What's hot (20)

ODP
JavaScript and jQuery Fundamentals
PPT
Java for Mainframers
PDF
Class notes(week 10) on applet programming
PPT
AspMVC4 start101
PPT
PDF
Spring aop
PDF
Java applet basics
PPTX
C# Security Testing and Debugging
PPTX
Selenium Automation in Java Using HttpWatch Plug-in
PDF
Using HttpWatch Plug-in with Selenium Automation in Java
PPT
Intro Java Rev010
PPTX
C#Web Sec Oct27 2010 Final
PPT
RomaFramework Tutorial Basics
PDF
Rest web service
PPTX
MVC Training Part 2
PPT
PPT
ASP.NET 05 - Exception Handling And Validation Controls
PDF
Laravel mail example how to send an email using markdown template in laravel 8
DOC
Applet
PDF
Best Laravel Eloquent Tips and Tricks
JavaScript and jQuery Fundamentals
Java for Mainframers
Class notes(week 10) on applet programming
AspMVC4 start101
Spring aop
Java applet basics
C# Security Testing and Debugging
Selenium Automation in Java Using HttpWatch Plug-in
Using HttpWatch Plug-in with Selenium Automation in Java
Intro Java Rev010
C#Web Sec Oct27 2010 Final
RomaFramework Tutorial Basics
Rest web service
MVC Training Part 2
ASP.NET 05 - Exception Handling And Validation Controls
Laravel mail example how to send an email using markdown template in laravel 8
Applet
Best Laravel Eloquent Tips and Tricks
Ad

Viewers also liked (20)

DOCX
PPS
Navidad Noel 2009 Show
PPT
Crooked Creek History
PDF
Microsoft Sharepoint and Java Application Development
PPS
Presentation Norman Dl Consulting (Eng)
PPTX
Creating Dynamic Web Application Using ASP.Net 3 5_MVP Alezandra Buencamino N...
PPTX
Scalable Java Application Development on AWS
PPT
Quantum Networks[1] Power Point
PPS
Test De Rapidez Mental
PDF
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
PPTX
Java, app servers and oracle application grid
PPT
Tomcat Server
PPS
PDF
Jyoti Vol.IX Bulletin of Rotary Club of Kalyan
PPT
Mitigation strategies for the protection of health care workers and first res...
PPTX
Soluciones 130220212358-phpapp01
PPS
PPT
Keen Sales Slide Share
Navidad Noel 2009 Show
Crooked Creek History
Microsoft Sharepoint and Java Application Development
Presentation Norman Dl Consulting (Eng)
Creating Dynamic Web Application Using ASP.Net 3 5_MVP Alezandra Buencamino N...
Scalable Java Application Development on AWS
Quantum Networks[1] Power Point
Test De Rapidez Mental
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
Java, app servers and oracle application grid
Tomcat Server
Jyoti Vol.IX Bulletin of Rotary Club of Kalyan
Mitigation strategies for the protection of health care workers and first res...
Soluciones 130220212358-phpapp01
Keen Sales Slide Share
Ad

Similar to Ta Javaserverside Eran Toch (20)

PPT
Ibm
PPTX
Jsp and jstl
PDF
Jsp tutorial
PPT
J2EE - JSP-Servlet- Container - Components
PPT
Developing Java Web Applications
PPTX
Introduction to JSF
PPT
Spring MVC
PPT
Introduction To ASP.NET MVC
PPT
1 java servlets and jsp
PPT
J2 Ee Overview
PPT
Struts 2 Overview
PPT
J2EE - Practical Overview
PPT
Spring and DWR
PPT
Wicket Introduction
DOCX
Server side programming bt0083
PPTX
C:\fakepath\jsp01
PPTX
JSR 168 Portal - Overview
PPT
Struts,Jsp,Servlet
PPT
Strutsjspservlet
Ibm
Jsp and jstl
Jsp tutorial
J2EE - JSP-Servlet- Container - Components
Developing Java Web Applications
Introduction to JSF
Spring MVC
Introduction To ASP.NET MVC
1 java servlets and jsp
J2 Ee Overview
Struts 2 Overview
J2EE - Practical Overview
Spring and DWR
Wicket Introduction
Server side programming bt0083
C:\fakepath\jsp01
JSR 168 Portal - Overview
Struts,Jsp,Servlet
Strutsjspservlet

More from Adil Jafri (20)

PDF
Csajsp Chapter5
PDF
Php How To
PDF
Php How To
PDF
Owl Clock
PDF
Phpcodebook
PDF
Phpcodebook
PDF
Programming Asp Net Bible
PDF
Tcpip Intro
PDF
Network Programming Clients
PDF
Jsp Tutorial
PDF
Csajsp Chapter10
PDF
Javascript
PDF
Flashmx Tutorials
PDF
Java For The Web With Servlets%2cjsp%2cand Ejb
PDF
Html Css
PDF
Digwc
PDF
Csajsp Chapter12
PDF
Html Frames
PDF
Flash Tutorial
PDF
C Programming
Csajsp Chapter5
Php How To
Php How To
Owl Clock
Phpcodebook
Phpcodebook
Programming Asp Net Bible
Tcpip Intro
Network Programming Clients
Jsp Tutorial
Csajsp Chapter10
Javascript
Flashmx Tutorials
Java For The Web With Servlets%2cjsp%2cand Ejb
Html Css
Digwc
Csajsp Chapter12
Html Frames
Flash Tutorial
C Programming

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Monthly Chronicles - July 2025

Ta Javaserverside Eran Toch

  • 1. Tutorial: Server-Side Web Applications with Java, JSP and Tomcat Eran Toch December 2004 Methodologies in Information Systems Development
  • 2. Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application Writing JavaBeans Writing JSPs Includes, session and application Model 2 Architecture
  • 3. Web Application vs. Web Site Web Site Web Application
  • 4. The Difference – cont’d Web sites are Static File based May include client’s JavaScript code Web Applications are Dynamic (output depend on input) Database based Multi-layered Session dependent (most of the times) Personalized (some of the times)
  • 5. Java Web Application Architecture JSP Application Server Browser Servlet Java Classes / EJB HTTP / HTML DB / ERP / Legacy
  • 6. Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application Writing JavaBeans Writing JSPs Includes, session and application Model 2 Architecture
  • 7. Tomcat Installation Go to: http://jakarta.apache.org/tomcat/ Download the latest version (currently 5.5.4) by going to: Downloads -> Binaries -> Tomcat 5.5.4. For Windows, download the exe version – with a Windows setup. The direct link: http://apache.fresh.co.il/jakarta/tomcat-5/v5.5.4/bin/jakarta-tomcat-5.5.4.exe For Linux, read the setup manual: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/setup.html
  • 8. Tomcat and Java 5 Please note that Tomcat v. 5.5.4 requires J2SE 1.5 (also known as J2SE 5) or above. If you want to use J2SE 1.4, download Tomcat 5.0.+
  • 9. Tomcat Installation – cont’d If you want Tomcat to startup every time the computer is rebooted, check the “service” option. If you wish to use Tomcat for only for development, it’s best to leave the service option unchecked.
  • 10. Tomcat Installation - Port You can configure the port that Tomcat will be using. If you want it to be available publicly (behind firewalls etc), change the default port to 80. Otherwise, leave it as it is (880). You can always change it later, in the [TOMCAT_HOME]/conf/server.xml configuration file.
  • 11. Running Tomcat Start Tomcat by running Tomcat monitor (Start Menu -> Apache Tomcat -> Monitor Tomcat), and click on Start. Point your browser to: http://localhost:8080 . If Tomcat works, you should see something like this If not, check out the logs (C:\[TOMCAT_HOME]\logs\stdout) and see what went wrong.
  • 12. Managing Tomcat Go to the management console by clicking on the “management” link in the Tomcat root homepage, or directly by going to: http :// localhost : 8080 / manager / html . The default username is “admin”, and the default password is ”” You can change it by changing the [TOMCAT_HOME]\conf\tomcat-users.xml.
  • 13. Managing Tomcat Console Web Application management Number of current sessions Start, stop, restart and un-deploy applications
  • 14. Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application Writing JavaBeans Writing JSPs Includes, session and application Model 2 Architecture
  • 15. Building A Web Application Build the following folder structure under [TOMCAT-HOME]\webapps Tomcat-home conf common webapps ... phones WEB-INF lib classes jsp This is the hard way… There are better
  • 16. Creating JSP Project in Eclipse Open a project for the JSP pages Choose the type “Simple project”
  • 17. Creating JSP Project – cont’d Choose the path to the jsp folder Click “Finish”
  • 18. Creating Java Classes Project Create a new project Choose “Java Project”
  • 19. Creating Java Project – cont’d Choose the path to the WEB-INF/classes folder
  • 20. Creating Java Project – cont’d Make sure the output build path is in the WEB-INF classes folder Necessary libraries could be added now
  • 21. Better ways Download MyEclipse IDE extension from: http://www.myeclipseide.com/ Download Lomboz plugin for Eclipse at: http://www.objectlearn.com/index.jsp Both of these plugins will give you: Easier deployment of projects JSP debugging JSP error detection (important!)
  • 22. Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application Writing JavaBeans Writing JSPs Includes, session and application Model 2 Architecture
  • 23. Our “Phones” Application Simple application that displays phone records from the database (stupid, shameless) Architecture: select_entry.jsp display_phone.jsp PhoneEntry.java DBConnector.java Database
  • 24. PhoneEntry.java package edu.technion.methodologies.phones ;   public class PhoneEntry { private int id = 0 ; private String name ; private String phone ; private String email ; public void load(int id ) { DBConnector.loadPhone(id, this ); } public void save () { if (id == 0 ) { id = DBConnector.insertPhone(this ); } else { DBConnector.updatePhone(id, this ); } } //getters and setters… }
  • 25. DBConnector.java See the advanced Java tutorial…
  • 26. Writing Scriplets in JSP Write HTML as normal Dynamic parts between <% %> Eg <HTML> <BODY> Hello!  The time is now <%= new java.util.Date() %> </BODY> </HTML>
  • 27. JSP Scripting Elements Expressions <%=  expression  %> evaluated and inserted into the output Scriptlets <%  code  %> inserted into the servlet's service method Declarations <%!  code  %> inserted into the body of the servlet class, outside of any existing methods
  • 28. JSP Directives There are two main types of directive: page lets you do things like import classes, customize the servlet superclass etc Include lets you insert a file into the servlet class at the time the JSP file is translated into a servlet. <%@ directive attribute=&quot;value&quot; %>
  • 29. select_entry.jsp <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <HTML> <HEAD> <TITLE> Phones Application </TITLE> </HEAD> <BODY> <form action = &quot;display_phone.jsp&quot; method = &quot;post&quot; > <table border = 0 > <tr> <td> ID: </td> <td><input type = &quot;text&quot; name = &quot;id&quot; ></td> </tr> <tr> <td> &nbsp; </td> <td><input type = &quot;submit&quot; ></td> </tr> </table> </form> </BODY> </HTML> HTML Header HTML form Nested HTML table structure HTML text input
  • 31. display_phone.jsp <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <%@ page import = &quot;edu.technion.methodologies.phones.*&quot; %> <HTML> <HEAD> <TITLE> Phone Entry </TITLE> </HEAD> <BODY> <% String idParam = request.getParameter( &quot;id&quot; ); int id = 0; if (idParam != null ){ id = Integer.parseInt(idParam); } PhoneEntry phoneEntry = new PhoneEntry(); phoneEntry.load(id); %> Handling the request Creating the JavaBean Importing libraries
  • 32. display_phone.jsp – cont’d <table border = 0 > <tr> <td> Name: </td> <td><b> <%= phoneEntry.getName() %> </b></td> </tr> <tr> <td> Phone: </td> <td> <%= phoneEntry.getPhone() %> </td> </tr> <tr> <td> Email: </td> <td> <%= phoneEntry.getEmail() %> </td> </tr> </table> </BODY> </HTML>
  • 34. Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application Writing JavaBeans Writing JSPs Includes, session and application Model 2 Architecture
  • 35. JSP Include Inserting elements into the JSP page in complication time <table border = &quot;0&quot; width = &quot;100%&quot; cellpadding = &quot;4&quot; > <tr bgcolor = &quot;99CCFF&quot; > <td><a href = &quot;select_entry.jsp&quot; > home </a></td> </tr> </table> Included JSP file
  • 36. JSP Include – cont’d … <BODY> <%@ include file = &quot;header.jsp&quot; %> <% … We add the include declarative into display_phone.jsp And we get:
  • 37. Session and Application Objects A session is an object associated with a visitor.  Data can be put in the session and retrieved from it Sessions are timed-out – the default is ~25 minutes The application object is accessed similarly, but is unique and global for the web application //Setting an object within the session session.setAttribute( &quot;last_searched_id&quot; , new Integer(id)); //Getting an object from the session Integer lastID = (Integer)session.getAttribute( &quot;last_searched_id&quot; ); out.println(lastID);
  • 38. Advanced Issues Servlets – have many advantages over JSP Inheritance Class structure Tag libraries Enterprise Java Beans J2EE Frameworks (WebLogic, Web Sphere, JBoss)
  • 39. Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application Writing JavaBeans Writing JSPs Includes, session and application Model 2 Architecture
  • 40. Model 2 Architecture recommended approach for designing medium- and large-sized Web applications An implementation of the Model-View-Controller (MVC) pattern Applications have 3 layers Model : containing all data and operations JSP classes or beans View : creating various presentations JSP – focus on static data Controller : receiving requests, updating the model, and delegating to views servlet
  • 41. Model 2 Architecture – cont’d .jsp .jsp Form request forward Database classes servlet VIEW CONTROLLER MODEL
  • 42. Struts Struts is an open source framework created within the Jakarta project by the Apache Software Foundation Supports Model-View-Controller (MVC) design pattern http://struts.apache.org/
  • 43. References Core Servlets and JavaServer Pages, Vol. 1: Core Technologies, Second Edition, by Marty Hall, Larry Brown Sun’s JSP Tutorial: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html JavaBeans Tutorial: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPBeans.html A set of advanced (and untidy) tutorials: http://www.coreservlets.com/