Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering

Slides:



Advertisements
Similar presentations
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
Advertisements

 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
DT211/3 Internet Application Development JSP: Processing User input.
J2EE Servlets and JSP Advanced topics Presented by Bartosz Sakowicz.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
MVC Architecture1 Usage Rules PowerPoint slides for use only in for-credit courses at degree-granting institutions Slides can be modified.
Integrating Servlets and JavaServer Pages Vijayan Sugumaran School of Business Administration Oakland University Parts of this presentation provided by.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Struts 2.0 an Overview ( )
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Applets & Servlets.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
What Are Beans? beans are simply Java classes that are written in a standard format. A bean class must have a zero-argument (default) constructor. A bean.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Fall CIS 764 Database Systems Design L8. Web ….
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
Model View Controller Architecture of Java Web Applications Dr. M V S Peri Sastry, Ph.D.[BITS-Pilani]
Model View Controller MVC Web Software Architecture.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
 Obtaining a RequestDispatcher Forwarding requests from servlets to dynamic resources  Forwarding requests from servlets to static resources  Using.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Portals: Architecture & Best Practices Greg Hinkle February 2005.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
USING JAVABEANS COMPONENT IN JSP DOCUMENTS. References Marty Hall. Core Servlet and Java Server Page. Sun Micro System. Prentice Hall PTR; 1 edition 2000.
JAVA SERVER PAGES -by Rubeena Memon Deepti Jain Jaya Thakar Jisha Vettuventra.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Chapter 14 Using JavaBeans Components in JSP Documents.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
Enterprise Java v050228MVC1 Model, View, Controller Web Architecture.
Java Server Pages By: Tejashri Udavant..
Scope and State Handling in JSPs
Design and Maintenance of Web Applications in J2EE
Engineering the Java Web Application (MVC)
Model-View-Controller Patterns and Frameworks
Introduction to Servlets
CS320 Web and Internet Programming Java Beans
CS320 Web and Internet Programming MVC Architecture
Scope and State Handling in Java Server Pages
Chengyu Sun California State University, Los Angeles
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Struts BY: Tejashri Udavant..
Presentation transcript:

Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering 19/12/2007

Fall 2007cs4202 Agenda Model View Controller Architecture Reference – –coreservlets.com

Why combine JSP and Servlets? Typical picture: use JSP to make it easier to develop and maintain the HTML content –For simple dynamic code, call servlet code from scripting elements –For slightly more complex applications, use custom classes called from scripting elements –For moderately complex applications, use beans and custom tags But, that's not enough –For complex processing, starting with JSP is awkward –Despite the ease of separating the real code into separate classes, beans, and custom tags –The assumption behind JSP is that a single page gives a single basic look

Fall 2007cs4204 Handling Single Requests (possibilities) Servlet only. Works well when: –Output is a binary type. E.g.: an image –There is no output. E.g.: you are doing forwarding or redirection as in Search Engine example. –Format/layout of page is highly variable. E.g.: portal. JSP only. Works well when: –Output is mostly character data. E.g.: HTML –Format/layout mostly fixed. Combination (MVC architecture). Needed when: –A single request will result in multiple substantially different looking results. –You have a large development team with different team members doing the Web development and the business logic. –You perform complicated data processing, but have a relatively fixed layout.

Fall 2007cs4205 MVC Flow of control

Fall 2007cs4206 MVC Misconceptions An elaborate framework is necessary –Frameworks are sometimes useful  Struts  JavaServer Faces (JSF) –They are not required!  Implementing MVC with the builtin RequestDispatcher works very well for most simple and moderately complex applications MVC totally changes your overall system design –You can use MVC for individual requests –Think of it as the MVC approach, not the –MVC architecture  Also called the Model 2 approach

Fall 2007cs4207 Implementing MVC with the RequestDispatcher 1. Define beans to represent the data 2. Use a servlet to handle requests –Servlet reads request parameters, checks for missing and malformed data, etc. 3. Populate the beans –The servlet invokes business logic (application-specific code) or data-access code to obtain the results. Results are placed in the beans that were defined in step Store the bean in the request, session, or servlet context –The servlet calls setAttribute on the request, session, or servlet context objects to store a reference to the beans that represent the results of the request

Fall 2007cs4208 Implementing MVC with the RequestDispatcher 5. Forward the request to a JSP page. –The servlet determines which JSP page is appropriate to the situation and uses the forward method of RequestDispatcher to transfer control to that page. 6. Extract the data from the beans. –The JSP page accesses beans with jsp:useBean and a scope matching the location of step 4. The page then uses jsp:getProperty to output the bean properties. –The JSP page does not create or modify the bean; it merely extracts and displays data that the servlet created.

Fall 2007cs4209 Request Forwarding

Fall 2007cs42010 jsp:useBean in MVC vs. in Standalone JSP Pages The JSP page should not create the objects –The servlet, not the JSP page, should create all the data objects. So, to guarantee that the JSP page will not create objects, you should use instead of The JSP page should not modify the objects –So, you should use jsp:getProperty but not jsp:setProperty.

Fall 2007cs42011 Scope Alternatives request – session – application – page – or just –This scope is not used in MVC (Model 2) architecture

Fall 2007cs42012 Data Sharing Servlet ValueObject value = new ValueObject(...); request.setAttribute("key", value); RequestDispatcher dispatcher = request.getRequestDispatcher ("/WEB-INF/SomePage.jsp"); dispatcher.forward(request, response); JSP <jsp:useBean id="key" type="somePackage.ValueObject" scope="request" />

Fall 2007cs42013 Variations Use response.sendRedirect instead of RequestDispatcher.forward Distinctions: with sendRedirect: –User sees JSP URL (user sees only servlet URL with RequestDispatcher.forward) –Two round trips to client (only one with forward) Advantage of sendRedirect –User can visit JSP page separately  User can bookmark JSP page Disadvantage of sendRedirect –Since user can visit JSP page without going through servlet first, JSP data might not be available  So, JSP page needs code to detect this situation

Fall 2007cs42014 Application Scope / Serlvet-Context Based Data Sharing Servlet synchronized(this) { ValueObject value = new ValueObject(...); getServletContext().setAttribute("key", value); RequestDispatcher dispatcher = request.getRequestDispatcher ("/WEB-INF/SomePage.jsp"); dispatcher.forward(request, response); } JSP 1.2 <jsp:useBean id="key" type="somePackage.ValueObject" scope="application" />

Fall 2007cs42015 Relative URLs in JSP pages Issue: –Forwarding with a request dispatcher is transparent to the client. Original URL is only URL browser knows about. Why does this matter? –What will browser do with tags like the following: … –Answer: browser treats them as relative to servlet URL Simplest solution: –Use URLs that begin with a slash

Fall 2007cs42016 Summary Use MVC (Model 2) approach when: –One submission will result in more than one basic look –Several pages have substantial common processing Architecture –A servlet answers the original request –Servlet does the real processing & stores results in beans  Beans stored in HttpServletRequest, HttpSession, or ServletContext –Servlet forwards to JSP page via forward method of RequestDispatcher –JSP page reads data from beans by means of jsp:useBean with appropriate scope (request, session, or application)

Fall 2007cs42017 Summary & Questions? That’s all for today!