OOSD Using Java CBTS Framework. 11/2/04CBTS2 Servlet  A servlet is a Java program that can extends Web server’s functionality.  Servlets interact with.

Slides:



Advertisements
Similar presentations
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
Advertisements

1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Apache Tomcat as a container for Servlets and JSP
Java Server Pages (JSP)
Apache Struts Technology
Java Servlets Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
Web MVC-2: Apache Struts Rimon Mikhaiel
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
JBoss Seam: Contextual Components Jason Bechtel
An introduction to Java Servlet Programming
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Introduction to Servlet & JSP
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Introduction to MVC and the Jakarta Struts Framework By Gyanendra Dwivedi Software Consultant.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Java Servlets & Java Server Pages Lecture July 2013.
3-Tier Web Application Architecture. Simple Log-in public String button1_action() { // TODO: Process the button click action. Return value is a navigation.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
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.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Introduction To HTML Dr. Magdi AMER. HTML elements.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Apache Struts Technology A MVC Framework for Java Web Applications.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Enterprise Java v050228MVC1 Model, View, Controller Web Architecture.
Introduction to Servlets
Introduction to Servlets
Handling Errors in Web Applications
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
In Class Assg 2 - solution
The Model Layer What is Model?
Directories and DDs 25-Apr-19.
CS122B: Projects in Databases and Web Applications Winter 2019
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Struts BY: Tejashri Udavant..
Presentation transcript:

OOSD Using Java CBTS Framework

11/2/04CBTS2 Servlet  A servlet is a Java program that can extends Web server’s functionality.  Servlets interact with a Web client in a request- response mechanism that is based on HTTP.  As a counterpart to Applet, a servlet runs in a Web container on the host of a Web server.  A servlet can invoke the appropriate logic in other Java classes to fulfill clients’ requests, and return the results to clients through the Web server.

11/2/04CBTS3 Processing HTTP Requests - I Browser Web Server Application Server Web container Database Http Request Http Response servlets Other classes View Controller Model The real power of servlets come from their ability to serve s controllers in the MVC pattern.

11/2/04CBTS4 Web container Processing HTTP Requests - II Browser Web Server Application Server Database Http Request Http Response servlets Model layer classes View Controller Model JSP can be used to further separate Java code with control logic and HTML tags. JSPs

11/2/04CBTS5 The HttpServlet API

Ctbs Form Login Action Servlet Login Form Login.jsp Select Exam.jsp User Mgr User Dao User Ctbs Form Select Exam Form 1.1 load 2. login 2.1 login 3. create 1. post 2.2 sql 4. redirect Login Use Case – object interaction

11/2/04CBTS7 Login.jsp Login Page Username <input name="username" value=' '> Password <input name="password" type="password" value=' '>

11/2/04CBTS8 The LoginAction Servlet public class LoginAction extends ActionServlet { public CtbsForm execute(CbtsForm prevPage) { LoginForm page = (LoginForm) prevPage; String username = page.getUsername(); String password = page.getPassword(); UserVo user = null; try { user = UserMgr.getUserInstance().login(username, password); } catch (ManagerException me) { prevPage.addError("Server Problem. Please try again!"); return prevPage; } if (user == null) { prevPage.addError("Wrong login info. Please try again!"); return prevPage; } else { //hard-coded for now String[] exams = {"Computer Ethics", "Object-Oriented Analysis & Design"}; return new SelectExamForm(exams); }

11/2/04CBTS9 The Base Servlet – the template public abstract class ActionServlet extends HttpServlet { private CbtsForm prevPage; private CbtsForm nextPage; public void init(ServletConfig config) throws ServletException { super.init(config); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //processRequest(request, response); loadPrevPage(request); nextPage = execute(prevPage); request.getSession().setAttribute("formObj", nextPage); response.sendRedirect(getFormName(nextPage)); } public abstract BaseForm execute(BaseForm prevPage); }

11/2/04CBTS10 The Base Servlet – from the prev. page protected void loadPrevPage(HttpServletRequest request) { prevPage = (CtbsForm)request.getSession().getAttribute("formObj"); BeanInfo pageInfo = null; //get the page attributes by class reflection try { pageInfo = Introspector.getBeanInfo(prevPage.getClass()); }catch (IntrospectionException ise) { } PropertyDescriptor[] pds = pageInfo.getPropertyDescriptors(); try { for (int i=0; i<pds.length; i++) { Method m = pds[i].getWriteMethod(); Object[] args = {request.getParameter(pds[i].getName())}; m.invoke(prevPage, args); } } catch (Exception iae) {} }

11/2/04CBTS11 The Base Servlet – to the next page protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { loadPrevPage(request); nextPage = execute(prevPage); request.getSession().setAttribute("formObj", nextPage); response.sendRedirect(getPageName(nextPage)); } private String getPageName(CbtsForm form) { String name = form.getClass().getName(); java.util.StringTokenizer tok = new java.util.StringTokenizer(name, "."); for (int i=0; i<tok.countTokens()-1; i++) { System.out.println(tok.nextToken()); } String formName = tok.nextToken(); formName = formName.substring(0, formName.length()-4); return formName + “.jsp”; } }

11/2/04CBTS12 The Base Form – a JavaBean public abstract class CbtsForm implements java.io.Serializable { private String errorMessage = ""; /** Creates a new instance of CbtsForm */ public CbtsForm() { } public void addError(String msg) { errorMessage += msg; } public String getError() { return errorMessage; }

11/2/04CBTS13 The LoginForm Page Bean public class LoginForm extends CbtsForm { private String username = ""; private String password; public LoginForm() { } public LoginForm(String username, String password) { this.username = username; this.password = password; } public String getUsername() { return username; } public String getPassword() { return password; } public void setUsername(String username) { this.username = username; } public void setPassword(String password) { this.password = password; } }

11/2/04CBTS14 The User Manager public class UserMgr { private DaoFactory dbFactory = DaoFactory.getDaoFactory(); private UserMgr() { } public static UserMgr getUserInstance() { return new UserMgr(); } public UserVo login(String uname, String pwd) throws ManagerException { UserVo user = null; try { user = dbFactory.getUserDao().login(uname, pwd); } catch (DatabaseException e) { } return user; }