Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)

Similar presentations


Presentation on theme: "CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)"— Presentation transcript:

1 CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)

2 Table of Contents Overview Architecture Model-View-Controller Architecture JSPs Servlets JavaBeans Database (MySQL)

3 Overview Computer Warehouse is a web application for a fictional company that allows a user to browse through a catalog of the company’s products such as laptops, desktops and various computer accessories. The user can select products, add products to a cart and purchase them using a credit card. The web application accepts the order and displays an invoice receipt for the purchase. The web application allows the user to join an email list.

4 Architecture HTML FilesJSP Files Other Java ClassesJavaBeansServlets Presentation Layer Business Rules Layer Database

5 Model-View-Controller (MVC) Pattern Controller ( DisplayProduct Servlet.class ) Database (MySQL) Model ( Product.class) Browser (Internet Explorer, Firefox) View ( Laptop.jsp ) HTTP response HTTP request

6 Model-View-Controller (MVC) Architecture MVC is a standard approach used to structure web applications. MVC pattern has three layers: the model, the view and the controller. Model defines business layer implemented by Javabeans. View defines presentation layer implemented by HTML and JSPs. Controller manages flow of data using Servlets.

7 Java Server Pages (JSP) A Java Server Page, or JSP, consists of Java code that is embedded within HTML Code. When a JSP is requested, the JSP engine translates it into a Servlet and compiles it. The Servlet is run by the servlet engine. For Java web applications Servlets are used to do the processing and JSP’s are used to present the user interface.

8 Servlets A Servlet is a Java class that extends the HttpServlet class and runs on a server within a servlet container. A Servlet is an object that receives a request and generates a response based on that request. Before requesting a servlet, it has to be mapped to a URL pattern using the Web.xml file.

9 Methods of a Servlet public void init() throws ServletException{}; public void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}; public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}; public void destroy () {};

10 Life cycle of a Servlet A server loads and initializes the Servlet by calling the init () method. The Servlet handles each browser request by calling the service () method. This method then calls another method to handle a specific HTTP request type. The server removes the Servlet by calling the destroy () method either when it has been idle for sometime or when server is shut down.

11 JavaBeans JavaBeans are classes written in the Java programming language conforming to following conventions: -  The class must have a public default constructor.  The class properties must be accessible using getter and settter methods (so-called accessor methods and mutator methods).  The class should be serializable. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects.

12 Database (MySQL) MySQL is an open source Database Management System (DBMS) Some of the features of MySQL are :-  Inexpensive  Fast  Easy to use  Portable  Support for SQL  Support for multiple clients

13 Steps to connect to a Database Load the drivers Get the connection Create the statement Execute the query Process the result set Close the connection

14 Steps to connect to a Database (example) String dbURL = "jdbc:mysql://localhost:3306/ClassProject"; String username = “xxx"; String password = “xxxx"; String productCode = request.getParameter("code"); Connection connection = DriverManager.getConnection(dbURL, username, password); Statement statement = connection.createStatement(); String query = "SELECT * FROM product WHERE code = '" + productCode + "'"; ResultSet rs = statement.executeQuery("SELECT * FROM classproject.product WHERE code = '" + productCode + "'");

15 Thank You


Download ppt "CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)"

Similar presentations


Ads by Google