Vinod sir struts 2 part 1

  • 2,600 views
Uploaded on

Basic Java Web Application using Eclipse, MVC Architecture & Struts Architecture.

Basic Java Web Application using Eclipse, MVC Architecture & Struts Architecture.

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,600
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
96
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Prof. Vinod Pillai.vinodthebest@gmail.comhttp://vinodthebest.wordpress.comwww.youtube.com/vinodthebest
  • 2. Agenda Part – I : Understanding Basics Web concepts & Struts Part – II : Setting Up Struts & Running basic App. Part – III : Struts 2 UI Tags & Integrating Tiles. Part – IV : Database + Session & Request Object. Prof. Vinod Pillai 2
  • 3. About Me: Currently I am working with Chaudhari Technical Institute – MCA as Assistant Professor since 2008. Academic counselor in MCA & BCA Department of Indira Gandhi National Open University (IGNOU), Ahmedabad since 2009. Visiting Faculty for MBA - Udaybhansinhji Regional Institute of Cooperative Management (URICM), Gandhinagar since 2009. Having 2.0 years of Industry experience + 4.0 teaching experience. Done Master of Computer Science (Wollongong University - Australia) with 70%. Done Bachelor of Computer Application (Gujarat University) with 87%. Cleared SCJP (Java Standard Edition 6 Programmer Certified Professional) with 95%. Major areas: C, C++, Java, Advance Java, Android, NT-II, C Project & C++ Project. Regular Jury Member of National Institute of Fashion Technology (NIFT- Gandhinagar) since 2009. Guided more than 25 MCA Groups for their Final Year Project. Guided 30 MCA Groups for C & C++ Project. Guided one of the MCA students for her NASA project which is being appreciated by a certificate. Prof. Vinod Pillai 3
  • 4. Part – I UnderstandingBasics Web Concepts & Struts Prof. Vinod Pillai 4
  • 5. Part – I : Understanding StrutsArchitecture.  Overview of Web Application.  Servlet.  JSP.  Java Beans.  MVC Architecture.  Simple MVC Base Application.  Understanding Struts 2 Architecture. Prof. Vinod Pillai 5
  • 6. Overview of Web Application Java Application = Desktop || Web || Mobile. Web Application :  Generation data dynamically not just simple static html pages.  Having some forms or login page.  Example: Gmail, Youtube, Facebook and many more. Web Application :  Simple Web Application.  Complex Web Application. Prof. Vinod Pillai 6
  • 7. Java Web Application General flow of client request and response: Prof. Vinod Pillai 7
  • 8. Java Web Application Key players for Java Web Application development:  Web Server.  Static HTML pages + CSS + JavaScript + Images + Videos.  Servlet.  JSP.  web.xml.  Library [If required]. Prof. Vinod Pillai 8
  • 9. Setting Up Web Applicaiton*Before we start we need the following tools: JDK 1.7 (Download) Eclipse Java EE IDE for Web Developers (Indigo) Tomcat 7 or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (Download) Prof. Vinod Pillai 9
  • 10. JDK 1.7http://www.oracle.com/technetwork/java/javase/downloads/index.html Prof. Vinod Pillai 10
  • 11. Eclipse Java EE IDEhttp://eclipse.org/downloads/ Prof. Vinod Pillai 11
  • 12. Apache Tomcat 7http://tomcat.apache.org/download-70.cgi Prof. Vinod Pillai 12
  • 13. Application Dev. [Eclipse] Starting Eclipse IDE Prof. Vinod Pillai 13
  • 14. Getting Started Selecting the workspace name: Prof. Vinod Pillai 14
  • 15. Application Dev. [Eclipse] Eclipse Main Window Prof. Vinod Pillai 15
  • 16. Hello World HTML in Eclipse Prof. Vinod Pillai 16
  • 17. Application Dev. [Eclipse] Step 2: [Creating Dynamic Web Project] Prof. Vinod Pillai 17
  • 18.  Open Eclipse and go to File -> New -> Project and select Dynamic Web Project in the New Project wizard screen. Prof. Vinod Pillai 18
  • 19.  Project Name: HelloWorld. Target runtime: <Select New Runtime> & show the path where you have unzipped the Tomcat Server. Dynamic web module version: 2.5. Prof. Vinod Pillai 19
  • 20.  HelloWorld Application Folder Structure Prof. Vinod Pillai 20
  • 21.  Creating HTML/JSP/Servlet: Prof. Vinod Pillai 21
  • 22.  Creating HTML/JSP/Servlet: Prof. Vinod Pillai 22
  • 23.  Running the application [Static / Dynamic Project]: Prof. Vinod Pillai 23
  • 24.  Running the application [Static / Dynamic Project]: Prof. Vinod Pillai 24
  • 25.  Final Output: Prof. Vinod Pillai 25
  • 26. HTML Page calling Servlet Prof. Vinod Pillai 26
  • 27. Java Web Application - Servlet Servlet  A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol.  Important methods:  void doGet(HttpServletRequest request, HttpServletResponse response)  void doPost(HttpServletRequest request, HttpServletResponse response) Prof. Vinod Pillai 27
  • 28.  Creating Servlet: Prof. Vinod Pillai 28
  • 29.  Servlet Code: Prof. Vinod Pillai 29
  • 30.  Telling HTML to call the Servlet: Prof. Vinod Pillai 30
  • 31. JSP Page calling Servlet Prof. Vinod Pillai 31
  • 32. Java Web Application - JSP JSP [JavaServer Pages]  JavaServer Pages (JSP) technology allows you to easily create Web content that has both static and dynamic components. JSP technology projects all the dynamic capabilities of Java Servlet technology but provides a more natural approach to creating static content. Prof. Vinod Pillai 32
  • 33.  Creating JSP: Prof. Vinod Pillai 33
  • 34.  Creating JSP: Prof. Vinod Pillai 34
  • 35. Java Web Application – Beans Javabean class is a type of java classes that is follow some rules for methods and naming. Major Rules of JavaBean class:  No-argument constructor.  The properties variables are private and accessed due the set and get methods.  The name of setter function is set followed by the property name but every first letter is upper case. (ex: setId() and getId()).  Setters and getters are public.  Getters have no parameter.  Setters have void return type. Prof. Vinod Pillai 35
  • 36.  Java Bean: Prof. Vinod Pillai 36
  • 37. Java Web Application – web.xml According to the Servlet 2.4 specification, every Web application should include a deployment descriptor (web.xml file). This file must be placed in the WEB- INF/ directory of the Web application. Be very careful when making modifications to this file (such as any additions or changes) because they will affect all Web applications running. Prof. Vinod Pillai 37
  • 38.  web.xml: Prof. Vinod Pillai 38
  • 39. MVCArchitecture Prof. Vinod Pillai 39
  • 40. MVC Architecture The MVC (Model-View-Controller) architecture is a way of decomposing an application into three parts:  Model  View  Controller. Model : A model represents an application’s data and contains the logic for accessing and manipulating that data. Any data that is part of the persistent state of the application should reside in the model objects. Prof. Vinod Pillai 40
  • 41. MVC Architecture View: View represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view modifies itself when a change in the model is communicated to the view. Controller : Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. Prof. Vinod Pillai 41
  • 42. Model View Controller (MVC) Prof. Vinod Pillai 42
  • 43.  MVC Application [Add two integer values] Prof. Vinod Pillai 43
  • 44.  Controller [Servlet]: Prof. Vinod Pillai 44
  • 45.  Model [Java Class / Bean or Both]: Prof. Vinod Pillai 45
  • 46.  View [Result JSP]: Prof. Vinod Pillai 46
  • 47.  Output: Prof. Vinod Pillai 47
  • 48. StrutsFramework Prof. Vinod Pillai 48
  • 49. Introduction Java Application = Desktop || Web || Mobile. Struts 2= Apache Struts Web Framework. Framework:  Peace of Software that Automates all tedious task.  Use Design patterns commonly agreed by Industry.  In built features that commonly needed by most of project. Prof. Vinod Pillai 49
  • 50. Jakarta Struts The Apache Struts web framework is a free open- source solution for creating Java web applications. Apache Struts was launched in May 2000, with version 1.0 officially released in July 2001. Why we need it?  Web applications based on JSP sometimes combines database code, page design code, and control flow code.  In practice, we find that unless these concerns are separated, larger applications become difficult to maintain. Prof. Vinod Pillai 50
  • 51. Jakarta Struts One way to separate concerns in a software application => Model-View-Controller (MVC) architecture. MVC  Model = Business or database code  View = Page design code  Controller = Navigational code. Struts framework is designed to help developers create web applications that utilize a MVC architecture. Prof. Vinod Pillai 51
  • 52. Struts 2 Apache Struts Project offers two major versions:  Struts 1 is recognized as the most popular web application framework for Java.  Struts 2 was originally known as WebWork 2.WebWork and Struts communities joined forces to create Struts 2. Struts 2 is a pull-MVC framework. i.e. the data that is to be displayed to user has to be pulled from the Action. Action class in Struts 2 act as the model in the web application. Unlike Struts, Struts 2 Action class are plain POJO objects thus simplifying the testing of the code. Prof. Vinod Pillai 52
  • 53. Struts 2 Struts2 also comes with power APIs to configure Interceptors that reduce greatly the coupling in application. The view part of Struts 2 is highly configurable and it supports different result-types such as Velocity, FreeMarker, JSP, etc. Prof. Vinod Pillai 53
  • 54. Struts 2 Architecture Prof. Vinod Pillai 54
  • 55. Struts 2 Architecture1. Request is generated by user and sent to Servlet container [web.xml].2. Servlet container invokes FilterDispatcher filter which in turn transfer the call to [struts.xml] and finds the appropriate action .3. One by one Intercetors are applied before calling the Action. Interceptors performs tasks such as Logging, Validation, File Upload, Double-submit guard etc.4. Action is executed and the Result is generated by Action if the state of Model is to be Change then do so. Prof. Vinod Pillai 55
  • 56. Struts 2 Architecture5. The output of Action is rendered in the view (JSP, Velocity, etc) and the result is ready to returned to the user.6. The response passes through the interceptors in reverse order to perform any clean-up or additional processing.7. Now the Control is with [Servlet Engine] and the result is rendered to the user. Prof. Vinod Pillai 56
  • 57. Part – I : Understanding StrutsArchitecture.  Overview of Web Application.  Servlet.  JSP.  Java Beans.  MVC Architecture.  Simple MVC Base Application.  Understanding Struts 2 Architecture. Prof. Vinod Pillai 57
  • 58. Part – ICompleted Prof. Vinod Pillai 58
  • 59. Thank Youvinodthebest@gmail.com Prof. Vinod Pillai 59