7.1.Design Patterns for Web Applications

7.1.Design Patterns for Web Applications - Web Applications...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Web Applications Engineering: Web Design Patterns and Guideline Service Oriented Computing Group, CSE, UNSW Week 7 Slides prepared by Dr. Helen Paik, CSE, UNSW References used for the Lecture: http://java.sun.com/blueprints/patterns/index.html Core J2EE patterns, Deepak Alur, John Crupi and Dan Marlks, Prentice Hall H. Paik, S. Venugopal (CSE, UNSW) COMP9321, 11s1 Week 7 1 / 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Different Layers in an Application Different solutions for each layer Presentation Layer I JSP, XSLT, CSS, HTML Business logic I Java classes Data Access Layer I Data Access Objects Data Store I RDBMS, OODBMS, XML Database H. Paik, S. Venugopal (CSE, UNSW) COMP9321, 11s1 Week 7 2 / 1
Background image of page 2
J2EE design guidelines: Web tier J2EE Web Tier includes two technologies : Servlets JSP pages Servlets: Java’s solution to the old CGI technology They have access to the complete Java programming language HTML code were placed into the Servlets – difficult to maintain JSP is designed to solve this problem . .. H. Paik, S. Venugopal (CSE, UNSW) COMP9321, 11s1 Week 7 3 / 1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
eg., Mixing HTML with Java coding in Servlet public class BadlyMixedServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, ... { boolean databaseOpen = false; response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println out.println("<html><head>"); out.println("<title>Servlet</title></head>"); out.println("<body>"); // go get a database connection . .. if (databaseOpen()) { out.println("<h1>Well Done!</h1>"); } else { out.println("<font color="red">Please make sure your database is running</font>"); out.println("<br>"); } out.println("</body></html>"); out.close(); } H. Paik, S. Venugopal (CSE, UNSW) COMP9321, 11s1 Week 7 4 / 1
Background image of page 4
Servlet design guidelines: When to use Servlets As a Controller public class ControllerServlet extends HttpServlet { // dispatching the request to the handler . .. if(VIEW CAR LIST ACTION.equals(actionName)) destinationPage = "/carList.jsp"; else(ADD CAR.equals(actionName)) destinationPage = "/AddCart.jsp"; else . .. // more action checking here . .. RequestDispatcher ds = getServletContext().getRequestDispatcher(destinationPage); ds.forward(request, response); } Use dispatcher forward (do not commit output before forwarding!) If your Servlet is emitting some HTML, you may want to re-think. H. Paik, S. Venugopal (CSE, UNSW) COMP9321, 11s1 Week 7 5 / 1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Servlet design guidelines: When to use Servlets To generate binary content: e.g., downloading a jar file public class CodeDownLoad extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) { res.setContentType("application/jar"); ServletContext ctx = getServletContext(); InputStream is = ctx.getResourceAsStream("/newPluginJar.jar"); // variables snipped . .. OutputStream os = res.getOutputStream();
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/20/2011 for the course COMP 9417 taught by Professor Some during the Three '11 term at University of New South Wales.

Page1 / 53

7.1.Design Patterns for Web Applications - Web Applications...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online