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.

Slides:



Advertisements
Similar presentations
Michelle Johnston, Firebird Services Ltd
Advertisements

8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Java Server Pages (JSP)
Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
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.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
DT211/3 Internet Application Development
DT211/3 Internet Application Development
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
CS320 Web and Internet Programming JSP Scripting Elements and Page Directives Chengyu Sun California State University, Los Angeles.
JSP Java Server Pages Reference:
DT228/3 Web Development JSP: Directives and Scripting elements.
Java Server Pages B.Ramamurthy. Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content.
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,
1 CS6320 – JSP L. Grewe 2 Java Server Pages Servlets require you to write out entire page delivered with print statements Servlets require you to write.
Three types of scripting elements: 1.Expressions 2.Scriptlets 3.Declarations Scripting elements.
Web programming for project students Dr Jim Briggs.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems JavaServer Pages (JSP)
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
JSP Java Server Pages Softsmith Infotech.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
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,
Chapter 10 Overview of JSP Technology. Understanding the need for JSP JSP technology enables to mix regular, static HTML with dynamically generated content.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
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.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Web App GUI: JSP Basics & Forms 3680 Enterprise Programming.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
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.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
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.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also works) nloads/packages/eclipse-
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.
JSP java server pages.
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.
Java Servlets.
Chengyu Sun California State University, Los Angeles
Invoking Java Code from JSP
Directories and DDs 25-Apr-19.
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

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 HTML into a String literal is really ugly

In the end, JSP is just a servlet Your JSP eventually becomes a full-fledged servlet running in your web app It is a lot like any other servlet, except that the servlet class is written for you-by the Container The Container takes what you’ve written in your JSP, translates it into a servlet class source (.java) file, the compile that into a Java servlet class Also, if you changes JSP files and redeploy them to Tomcat, you do not have to restart tomcat in order to make the changes to be effective

Container translates JSP into Servlet This is the servlet tranlated from MyJSP.jsp

JSP Pauline wants to use JSPs in her web apps She understands that you can put regular old Java code in a JSP using a scriptlet which just means Java code within a tag

class MyClass { float aFloat; } class MyClass { static float aFloat; } Instance variable Class variable Instance variable is created for each instance of a class, the runtime system allocates class variables once per class regardless of the number of instances created of that class.

JSP When she deploys it and runs it, she got an exception page

Import packages You can put import statement in a JSP…you just need a directive  You may use the page directive to import packages A directive is a way for you to give special instructions to the Container at page translation time  Directives come in three flavors: page, include, and taglib

Import packages You can import a single package  E.g., You can also import multiple packages  E.g.,

Expression element Part of the whole point of JSP is to avoid println()!  JSP expression element automatically prints out whatever you put between the tags  Please remember that there is no semicolon when using expression element E.g.

Expression element The container takes everything you type between the and puts it in as the argument to a statement that prints to the implicit response PrintWriter out. When the Container sees this: It turns it into this out.print(Counter.getCount());

So far we’ve seen three element types Scriptlet: Directive: Expression:

Question

Declaring a variable in a scriptlet The variable declaration is legal, but it does not quite work the way we want. The same page is displayed no matter how many times the page is hit

All scriptlet and expression code lands in a service method.That means varaibles declared in a scriptlet are always LOCAL variables.

Declaration There is another JSP element called a declaration Anything between the tag is added to the class outside the service method

Time to see real generated servlet The real generated servlet is put under a directory of tomcat  E.g., I have a counter.jsp file under the directory C:\tomcat \webapps\ct The generated servlet file is located at:  C:\tomcat \work\Catalina\localhost\counter\org\apache\jsp\counter_jsp.java When you look at the generated servlet code, you did not see doGet() or doPost() methods there. Instead, you see a service method called _jspService()  This is because this _jspService() is called by the servlet superclass’s overridden service() method

Implicit object With implicit objects, you can write a JSP knowing that your code is going to be part of a servlet

Implicit object For example, you can put the following scriptlet into your JSP: <% String[] picked = request.getParameterValues(“fruits”); …….. %> This extract the parameter fruits that reflected what the user selected in a group of checkboxes in a HTML page