Principles of Software Development

Slides:



Advertisements
Similar presentations
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Advertisements

Object-Oriented Enterprise Application Development JavaServer Pages.
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
JSP – Java Server Pages Part 1 Representation and Management of Data on the Internet.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
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,
Web programming for project students Dr Jim Briggs.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
© Yaron Kanza Server-Side Programming using Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
JSP Tag Library CSCI 4300 Notes from Steve Small, /jw-0228-jstl.html.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
Introduction to Java Server Pages (JSPs) Robert Thornton.
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.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC.
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.
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 SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Chapter 7 Using Custom Tag Libraries and the JSP Standard Tag Library.
SE-2840 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
1 (Server-Side Programming using Java Server Pages) cs
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Java Server Pages (JSP)
CS-4220 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
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.
Web Technologies Java Beans & JSP By Praveen Kumar G.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 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,
JSP JavaServer Pages. What is JSP? Java based technology that simplifies the development of dynamic web sites JSP pages are HTML pages with embedded code.
® IBM Software Group © 2007 IBM Corporation JSP Tag Files
JSP java server pages.
JSP Elements Chapter 2.
CS3220 Web and Internet Programming Introduction to Java Servlets
JSP Based on
JSP: Actions elements and JSTL
Principles of Software Development
Server-Side Java Programming
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Developing JavaServer Pages
COMP9321 Web Application Engineering Semester 2, 2017
Principles of Software Development
Java Servlets.
Introduction to JSP Java Server Pages
Principles of Software Development
Knowledge Byte In this section, you will learn about:
Chengyu Sun California State University, Los Angeles
JSP Syntax.
Servlets.
Java Server Pages.
Servlets and Java Server Pages
Java Server Pages (JSP)
COP 4610L: Applications in the Enterprise Spring 2005
JSP implicit objects & directive elements
COSC 2956 Internet Tools Java Server Pages.
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.
Web Technologies Java Beans & JSP
Presentation transcript:

Principles of Software Development JSP CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu

Outline JSP Program USC CSCI 201L

JSP 3-Tier Architecture Client Server Web/Application Server Database USC CSCI 201L

JSP Because embedding HTML, CSS, and JavaScript as the output of a servlet is quite tedious, Java has a way to instead embed Java in your HTML file We can do this through a Java Server Page (JSP) JSPs get converted to servlets the first time they are accessed, compiled, and made available dynamically by the application server A JSP will be a file that looks like client-side code with embedded Java within special tags Declaration <%! %> Directive <%@ %> Expression <%= %> Scriptlet <% %> JSTL – explained in a later slide USC CSCI 201L

My First JSP 1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 pageEncoding="ISO-8859-1"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <title>My First JSP</title> 7 </head> 8 <body> 9 <h1>Hello CSCI 201</h1> 10 <% System.out.println("hello world"); %> 11 </body> 12 </html> USC CSCI 201L

Generated Servlet (partial service method) 1 try { 2 response.setContentType("text/html; charset=ISO-8859-1"); 3 pageContext = _jspxFactory.getPageContext(this, request, response, null, 4 true, 8192, true); 5 _jspx_page_context = pageContext; 6 application = pageContext.getServletContext(); 7 config = pageContext.getServletConfig(); 8 session = pageContext.getSession(); 9 out = pageContext.getOut(); 10 _jspx_out = out; 11 out.write("\r\n"); 12 out.write("<!DOCTYPE html>\r\n"); 13 out.write("<html>\r\n"); 14 out.write(" <head>\r\n"); 15 out.write(" <title>My First JSP</title>\r\n"); 16 out.write(" </head>\r\n"); 17 out.write(" <body>\r\n"); 18 out.write(" <h1>Hello CSCI 201</h1>\r\n"); 19 out.write(" "); 20 System.out.println("hello world"); 21 out.write("\r\n"); 22 out.write(" </body>\r\n"); 23 out.write("</html>\r\n"); Location of compiled JSP C:\Users\jeffadmin\workspace\ .metadata\.plugins\ org.eclipse.wst.server.core\tmp1\ work\Catalina\localhost\ TestWeb2\org\apache\jsp USC CSCI 201L

My Second JSP 1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 pageEncoding="ISO-8859-1"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <title>Loops</title> 7 </head> 8 <body> 9 <h1>Hello CSCI 201</h1> 10 <% 11 for (int i=0; i < 4; i++) { 12 %> 13 <font size="+<%= i %>">Font Size of +<%= i %></font><br /> 14 <% 15 } 16 %> 17 </body> 18 </html> USC CSCI 201L

Color JSP 1 <%@ page language="java" 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>Color JSP</title> 6 <%! 7 String getColor(int r, int g, int b) { 8 String color = ""; 9 color += makeHex(r); 10 color += makeHex(g); 11 color += makeHex(b); 12 return color; 13 } 14 15 String makeHex(int c) { 16 String hexString = Integer.toHexString(c); 17 if (hexString.length() == 1) { 18 hexString = "0" + hexString; 19 } 20 return hexString; 21 } 22 %> 23 </head> 24 <body> 25 <h1>Color Table</h1> 26 <table> 27 <tr> 28 <th>Red</th> 28 <th>Green</th> 29 <th>Blue</th> 30 <th>Color</th> 31 </tr> 32 <% 33 for (int red=0; red < 255; red+=50) { 34 for (int green=0; green < 255; green+=50) { 35 for (int blue=0; blue < 255; blue+=50) { 36 %> 37 <tr> 38 <td><%= red %></td> 39 <td><%= green %></td> 40 <td><%= blue %></td> 41 <% 42 String color = getColor(red, green, blue); 43 %> 44 <td style="background-color:#<%= color %>;"> </td> 45 </tr> 46 <% 47 } 48 } 49 } 50 %> 51 </table> 52 </body> 53 </html> USC CSCI 201L

Color JSP Generated HTML 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Color JSP</title> 5 </head> 6 <body> 7 <h1>Color Table</h1> 8 <table> 9 <tr><th>Red</th><th>Green</th><th>Blue</th><th>Color</th></tr> 10 <tr> 11 <td>0</td> 12 <td>0</td> 13 <td>0</td> 14 <td style="background-color:#000000;"> </td> 15 </tr> 16 <tr> 17 <td>0</td> 18 <td>0</td> 19 <td>50</td> 20 <td style="background-color:#000032;"> </td> 21 </tr> 22 <tr> 23 <td>0</td> 24 <td>0</td> 25 <td>100</td> 26 <td style="background-color:#000064;"> </td> 27 </tr> ... 1743 </table> 1744 </body> 1745 </html> USC CSCI 201L

JSPs and HTML Forms JSPs (which get converted to servlets) can be used to process the data submitted from an HTML form through the request variable JSPs have a number of implicit variables HttpServletRequest request HttpServletResponse response PrintWriter out HttpSession session ServletContext application ServletConfig config JSPWriter pageContext HttpServlet this Exception exception USC CSCI 201L

JSP Form Example 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Sample Form</title> 5 </head> 6 <body> 7 <form name="myform" method="GET" action="FormServlet"> 8 First Name <input type="text" name="fname" /><br /> 9 Last Name <input type="text" name="lname" /><br /> 10 <input type="submit" name="submit" value="Submit" /> 11 </form> 12 </body> 13 </html> USC CSCI 201L

JSP Form Example USC CSCI 201L 1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 pageEncoding="ISO-8859-1"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <title>Form Data Processing</title> 7 </head> 8 <body> 9 <% 10 String fname = request.getParameter("fname"); 11 String lname = request.getParameter("lname"); 12 %> 13 <h1>Submitted Data</h1> 14 First Name:<strong><%= fname %></strong><br /> 15 Last Name:<strong><%= lname %></strong> 16 </body> 17 </html> USC CSCI 201L

JSTL The Java Server Pages Standard Tag Library (JSTL) is a collection of useful JSP tags that have core functionality for many JSP applications The idea with JSTL was to keep front-end programmers from having to learn Java while allowing them to write code with similar functionality There are five tag library groups in JSTL Core tags - <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> Formatting tags - <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> SQL tags - <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> XML tags - <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> JSTL functions - <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> To use JSTL, you must place jstl-1.2.jar in the lib directory of your Tomcat installation, then restart Tomcat USC CSCI 201L

JSTL Example 1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 pageEncoding="ISO-8859-1"%> 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <title>Form Data Processing</title> 8 </head> 9 <body> 10 <c:set var="fname" value="${param.fname}" /> 11 <c:set var="lname" value="${param.lname}" /> 12 <h1>Submitted Data</h1> 13 First Name:<strong><c:out value="${fname}" /></strong><br /> 14 Last Name:<strong><c:out value="${lname}" /></strong> 15 </body> 16 </html> USC CSCI 201L

JSP Scope Different variables can have different scope in JSPs There are four different scopes in JSPs Application Session Page Request The following variable would remain in scope as long as the session is valid <c:set var="fname" value="${param.fname}" scope="session“ /> USC CSCI 201L

More JSP For more information on JSPs For more information on JSTL Go to http://docs.oracle.com/javaee/5/tutorial/doc/bnagy.html Go through one of the many JSP tutorials online For more information on JSTL Go to http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/ Go to https://jstl.java.net/

Outline JSP Program USC CSCI 201L

Program Modify the program you created during the Servlet lecture to have the HTML form submit to a JSP instead. Program USC CSCI 201L