Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)

Slides:



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

8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Michael Brockway Application Integration JavaServer Pages l Introduction & Overview l Implicit Objects l Scripting l Standard Actions l Directives l References.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
Writing Enterprise Applications with J2EE (First lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
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:
Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
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,
Writing Enterprise Applications with J2EE (Fifth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems JavaServer Pages (JSP)
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.
Java web development Servlet & Java server pages.
CSCI 6962: Server-side Design and Programming History and Background.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
Writing Enterprise Applications with J2EE (Second lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
JSP Java Server Pages Softsmith Infotech.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jordan Anastasiade. All rights reserved.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
J2EE Structure & Definitions Catie Welsh CSE 432
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.
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Chapter 7 Being a JSP. JSP introduction JSP is a solution for two issues  Servlet is difficult for HTML designers since they may not know Java  Formatting.
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.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
3/6/00jsp00 1 Java Server Pages Nancy McCracken Northeast Parallel Architectures Center at Syracuse University.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
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 -by Rubeena Memon Deepti Jain Jaya Thakar Jisha Vettuventra.
 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.
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.
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.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Java Server Pages By: Tejashri Udavant..
Java Servlets.
Scripted Page Web App Development (Java Server Pages)
Java Server Pages B.Ramamurthy.
Objectives In this lesson you will learn about: Need for servlets
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.
Presentation transcript:

Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)

Using JSPs instead of Servlets JSPs let you put segments of servlet code directly into a static HTML page. When the JSP Page is loaded by a browser, the servlet code executes and the application server creates, compiles, loads, and runs a background servlet to execute the servlet code segments and return an HTML page or print an XML report. This lesson changes the WAR file to use a JSP Page instead of BonusServlet. Required steps: Create the JSP Page Change bonus.html Remove the WAR File and create a new one Verify, deploy and run the J2EE Application

Create the JSP Page A JSP Page looks like an HTML page with servlet code segments embedded between various forms of leading ( ) JSP tags. There are no HttpServlet methods such as init, doGet, or doPost. Instead, the code that would normally be in these methods is embedded directly in the JSP Page using JSP scriptlet tags. The following Bonus.jsp is equivalent to BonusServlet. Note that JSP tags cannot be nested. For example, you cannot nest a JSP comment tag within a JSP scriptlet tag.

Bonus.jsp (I) Bonus Calculation <% strMult = request.getParameter("MULTIPLIER"); socsec = request.getParameter("SOCSEC"); integerMult = new Integer(strMult); multiplier = integerMult.intValue(); bonus = ; %> <% InitialContext ctx = new InitialContext(); Object objref = ctx.lookup("calcs"); CalcHome homecalc = (CalcHome) PortableRemoteObject.narrow(objref, CalcHome.class); %>

Bonus.jsp (II) <%-- Comment Scriptlet to create session Bean, call calcBonus method, and retrieve a database record by the social security number (primary key) --%> <% try { Calc theCalculation = homecalc.create(); Bonus theBonus = theCalculation.calcBonus(multiplier,bonus,socsec); Bonus record = theCalculation.getRecord(socsec); %> Bonus Calculation Social security number retrieved: Bonus Amount retrieved: <% } catch (javax.ejb.DuplicateKeyException e) { String message = e.getMessage(); %> Social security number passed in: Multiplier passed in: Error:

Comments The first seven lines of Bonus.jsp show straight HTML followed by a JSP comment. JSP comments are similar to HTML comments except they start with <%-- instead of <!--, which is how they look in HTML. You can use either JSP or HTML comments in a JSP file. HTML comments are sent to the client’s web browser where they appear as part of the HTML page, and JSP comments are stripped out and do not appear in the generated HTML.

Directives JSP directives are instructions processed by the JSP engine when the JSP Page is translated to a servlet. The directives used in this example tell the JSP engine to include certain packages and classes. Directives are enclosed by the directive tags. Example of directives in Bonus.jsp :

Declarations JSP declarations let you set up variables for later use in expressions or scriptlets. You can also declare variables within expressions or scriptlets at the time you use them. The scope is the entire JSP Page, so there is no concept of instance variables. That is, you do not have to declare instance variables to be used in more than one expression or scriptlet. Declarations are enclosed by. You can have multiple declarations. For example,.

Scriptlets JSP scriptlets let you embed java code segments into the JSP page. The embedded code is inserted directly into the generated servlet that executes when the page is requested. This scriptlet uses the variables declared in the directives described above. Scriptlets are enclosed by the scriptlet tags. Example of a scriptlet in Bonus.jsp : <% strMult = request.getParameter("MULTIPLIER"); socsec = request.getParameter("SOCSEC"); integerMult = new Integer(strMult); multiplier = integerMult.intValue(); bonus = ; %>

Predefined Variables A scriptlet can use the following predefined variables: session, request, response, out, and in. This example uses the request predefined variable, which is an HttpServletRequest object. Likewise, response is an HttpServletResponse object, out is a PrintWriter object, and in is a BufferedReader object. Predefined variables are used in scriptlets in the same way they are used in servlets, except you do not declare them. Example of use of predefined variables in Bonus.jsp : <% strMult = request.getParameter("MULTIPLIER"); socsec = request.getParameter("SOCSEC");...

Expressions JSP expressions let you dynamically retrieve or calculate values to be inserted directly into the JSP Page. In this example, an expression retrieves the social security number from the Bonus entity bean and puts it on the JSP page. Example of use of expressions in Bonus.jsp : Bonus Calculation Social security number retrieved: Bonus Amount retrieved:

JSP-Specific Tags The JavaServer Pages 1.1 specification defines JSP-specific tags that let you extend the JSP implementation with new features and hide complexity from visual designers who need to look at the JSP page and modify it. The JSP example in this lesson does not use any JSP-specific tags. The JSP-specific tags defined in the 1.1 specification are the following: jsp:forward and jsp:include to instruct the JSP engine to switch from the current page to another JSP page. jsp:useBean, jsp:setProperty, and jsp:getProperty let you embed and use JavaBeans technology inside a JSP Page. jsp:plugin automatically downloads the appropriate Java Plug-In to the client to execute an applet with the correct Java platform.

Change bonus.html Bonus Calculation Enter social security Number: Enter Multiplier: The only change you need to make to bonus.html is to have the ACTION parameter in the HTML form invoke Bonus.jsp instead of BonusServlet.

Create a new Web Component Upon the removal of the old WAR file, we have to make a new one containing both Bonus.jsp and bonus.html. WAR display name: BonusWar Component file: Bonus.jsp

Run the J2EE Appl. The web server runs on port 8000 by default. To open the bonus.html page point your browser to which is where the Deploy tool put the HTML file.