JavaServerPages Some examples. About JSP Java server pages are a combination of html (or xml), java code appearing within tagged regions, and structures.

Slides:



Advertisements
Similar presentations
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
Advertisements

JSP and Servelets.
JSP and web applications
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
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.
Apache Struts Technology
© Yaron Kanza Advanced Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Servlets Enterprise Systems Programming. Servlets  Servlets: server-side Java programs that enable dynamic processing of web-based requests  Web-based.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
An introduction to Java Servlet Programming
JSP Tag Extensions And Java Bean. JSP Tag Extensions Tag extensions look like HTML (or rather, XML) tags embedded in a JSP page. They have a special meaning.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
DT211/3 Internet Application Development
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
DT228/3 Web Development JSP: Directives and Scripting elements.
Web Development in Java Andrew Simpson. Overview Background Language Details Java Server Pages (JSP) Servlets Database Connectivity (JDBC) Samples and.
MC365 Application Servers: Java Server Pages (JSP’s) and Session Management.
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,
Q: According to Intel, the Pentium conforms to the IEEE standards 754 and 854 for floating point arithmetic. If you fly in aircraft designed using a Pentium,
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.
Java Servlets and JSP.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Struts 2.0 an Overview ( )
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
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.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
JSP Java Server Pages Softsmith Infotech.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
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.
 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,
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
COMP 321 Week 11. Overview Lab 8-1 Solution Tag Files Custom Tags Web Application Deployment.
Chapter 7 Using Custom Tag Libraries and the JSP Standard Tag Library.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.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.
COMP 321 Week 10. Overview Using Beans in JSP Expression Language JSTL Lab 10-1 Introduction Exam Review.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
JSP Custom Tags. Prerequisites Servlet API Mapping to JSP implicit objects JavaServer Pages Basic syntax Implementation via servlet API XML.
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.
Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also works) nloads/packages/eclipse-
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
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,
DT228/3 Web Development JSP: Actions elements and JSTL.
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.
CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.
CS3220 Web and Internet Programming Custom Tag Library
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.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
MSIS 655 Advanced Business Applications Programming
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
Java Servlets and JSP.
Presentation transcript:

JavaServerPages Some examples

About JSP Java server pages are a combination of html (or xml), java code appearing within tagged regions, and structures and functions called via other pages or tag libraries. A JSP is compiled when a request is made for the page. You’ll notice that the first request takes longer than subsequent requests. Otherwise, a JSP is “human-readable” and is placed somewhere in your webapp, in the root or some subdirectory. Reference to JSP does not need to be made in web.xml… The page is found via the URL, compiled and delivered (or error messages appear).

About JSP JSP are compiled and executed as servlets. You can’t implement JSP technology without a servlet container. Tomcat comes with many sample JSP and you can run them or view their code.

Tomcat jsp examples

EL: the expression language

A little of the EL arithmetic example: note use of backslash Expression Result \${1} ${1} \${1 + 2} ${1 + 2} \${ } ${ } \${1.2E } ${1.2E }

There are some cute and engaging examples, all with source code

panels

Hello World? It doesn’t look like much but…

The jsp taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %> JSP 2.0 Examples - Hello World SimpleTag Handler JSP 2.0 Examples - Hello World SimpleTag Handler This tag handler simply echos "Hello, World!" It's an example of a very basic SimpleTag handler with no body. Result:

The tag handler java class package jsp2.examples.simpletag; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.SimpleTagSupport; import java.io.IOException; /** * SimpleTag handler that prints "Hello, world!" */ public class HelloWorldSimpleTag extends SimpleTagSupport { public void doTag() throws JspException, IOException { getJspContext().getOut().write( "Hello, world!" ); } }

Java and jsp It is quite common to combine java classes (especially beans) with jsp. Beans typically handle the logic and jsp handles presentation.

Temp converter v0: Html points to a jsp <!-- tempconvert0.html A document that displays a form that collects a Celsius temperature from a client and calls a scriptlet to convert it to Fahrenheit --> Get a Celsius temperature Celsius temperature:

tempconvert0.jsp <!-- tempconvert0.jsp A document that converts a Celsius temperature received from tempconvert0.html to Fahrenheit --> Temperature converter <% // embedded java code…Get the Celsius temperature from the form String strCtemp = request.getParameter("ctemp"); float ftemp; // convert the value to Fahrenheit ftemp = 1.8f * Integer.parseInt(strCtemp) f;// I changed this a little %> <!-- Use an expression to display the value of the Fahrenheit temperature --> Fahrenheit temperature:

Running the example

scriptlets You can start and end java control structures between jsp tags, as in ….. This is a handy way to embed run-time structure into html

Using scriptlets to do temp conversion

tempconvert1.jsp part one <!-- tempconvert1.jsp A document that collects a Celsius temperature from a client and uses a scriptlet to convert it to Fahrenheit --> Temperature converter <% // Get the Celsius temperature from the form String strCtemp = request.getParameter("ctemp"); float ftemp; // If this is not the first request (there was a form value), // convert the value to Fahrenheit if (strCtemp != null) { ftemp = 1.8f * Integer.parseInt(strCtemp) f; %>

tempconvert1.jsp part 2 <!-- Use an expression to display the value of the Fahrenheit temperature --> Fahrenheit temperature: <!-- Code for the end of the then clause compound statement --> <% } //** end of if (strCtemp !=... else { %> <!-- This is the first request, so display the form to collect the Celsius temperature --> Celsius temperature: <!-- Code for the end of the else clause compound statement --> <% } //** end of else clause %>

The standard tag library… same thing again <!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN" " <!-- tempconvert2.html Get a temperature in Celsius and call a JSTL JSP document (tempconvert2.jsp) to convert it to Fahrenheit --> Get a Celsius temperature Celsius temperature:

tempconvert2.jsp… note tag lib prefix “c” <!-- tempconvert2.jsp Convert a given temperature in Celsius to Fahrenheit. Called by tempconvert2.html --> taglib prefix = "c" uri = " %> Temperature converter Given temperature in Celsius: Temperature in Fahrenheit:

Running tempconvert2

Page can post to itself, e.g., using jstl “if” Check if this is post or get:.

Same again, but a jsp page has itself as action target…looks same a previous <!-- tempconvert3.jsp Convert a given temperature in Celsius to Fahrenheit This is both the request and the response document --> taglib prefix = "c" uri = " %> Temperature converter Celsius temperature: <input type = "submit" value = "Convert to Fahrenheit" /> Given temperature in Celsius: Temperature in Fahrenheit:

Same, but using radio buttons <!-- tempconvert4.jsp Convert a given temperature in Celsius to Fahrenheit This is both the request and the response document --> taglib prefix = "c" uri = " %> Temperature converter to Fahrenheit to Celsius temperature to convert: <input type = "submit" value = "Convert" />

tempconvert4.jsp continued Temperature in Fahrenheit: Temperature in Celsius:

run

More radio buttons taglib prefix = "c" uri = " %> Payment type <input type = "radio" name = "payment" value = "visa" checked = "checked" /> Visa <input type = "radio" name = "payment" value = "mc" /> Master Charge <input type = "radio" name = "payment" value = "discover" /> Discover <input type = "radio" name = "payment" value = "check" /> Check

continued mc discover visa check

Post merely outputs the payment (rb) selected