Java Server Pages JSP

Similar documents
JavaServer Pages (JSP)

JSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP:

Servlet And JSP. Mr. Nilesh Vishwasrao Patil, Government Polytechnic, Ahmednagar. Mr. Nilesh Vishwasrao Patil

Enterprise Computing with Java MCA-305 UNIT II. Learning Objectives. JSP Basics. 9/17/2013MCA-305, Enterprise Computing in Java

Advantage of JSP over Servlet

Unit 5 JSP (Java Server Pages)

Java Server Pages. Copyright , Xiaoping Jia. 7-01/54

Basic Principles of JSPs

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

Unit 4 Java Server Pages

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY.

DEZVOLTAREA APLICATIILOR WEB LAB 4. Lect. Univ. Dr. Mihai Stancu

COMP9321 Web Application Engineering

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, JSPs 1

COMP9321 Web Application Engineering

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

First Simple Interactive JSP example

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

JavaServer Pages. What is JavaServer Pages?

Servlet and JSP Review

Java E-Commerce Martin Cooke,

Trabalhando com JavaServer Pages (JSP)

JSP Scripting Elements

ユーザー入力およびユーザーに 出力処理入門. Ivan Tanev

Trabalhando com JavaServer Pages (JSP)

01KPS BF Progettazione di applicazioni web

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer JSP

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer JSP

COMP9321 Web Application Engineering

CSC309: Introduction to Web Programming. Lecture 10

SNS COLLEGE OF ENGINEERING, Coimbatore

JAVA SERVLET. Server-side Programming INTRODUCTION

ServletConfig Interface

AJP. CHAPTER 5: SERVLET -20 marks

CE212 Web Application Programming Part 3

Java Server Pages(JSP) Unit VI

Volume 1: Core Technologies Marty Hall Larry Brown. Controlling the Structure of Generated Servlets: The JSP page Directive

6- JSP pages. Juan M. Gimeno, Josep M. Ribó. January, 2008

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

JSP MOCK TEST JSP MOCK TEST III

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests

JSP CSCI 201 Principles of Software Development

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

INVOKING JAVA CODE WITH JSP SCRIPTING ELEMENTS. Topics in This Chapter

Lab session Google Application Engine - GAE. Navid Nikaein

JSP source code runs on the web server via JSP Servlet Engine. JSP files are HTML files with special Tags

About the Authors. Who Should Read This Book. How This Book Is Organized

SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY- VIRUDHUNAGAR

Module 4: SERVLET and JSP

Advanced Internet Technology Lab # 4 Servlets

The Servlet Life Cycle

Unit 4. CRM - Web Marketing 4-1

Servlets by Example. Joe Howse 7 June 2011

Servlet Basics. Agenda

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

Session 20 Data Sharing Session 20 Data Sharing & Cookies

Servlets. An extension of a web server runs inside a servlet container

Watch Core Java and Advanced Java Demo Video Here:

Introduction. This course Software Architecture with Java will discuss the following topics:

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Oracle 1z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Practice Test. Version:

S imilar to JavaBeans, custom tags provide a way for

Advanced Web Technology

JAVA. Web applications Servlets, JSP

Servlet Fudamentals. Celsina Bignoli

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,

Université du Québec à Montréal

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

UNIT -5. Java Server Page

Servlets and JSP (Java Server Pages)

AIM. 10 September

Unit-4: Servlet Sessions:

Java4570: Session Tracking using Cookies *

Using Java servlets to generate dynamic WAP content

Session 10. Form Dataset. Lecture Objectives

directive attribute1= value1 attribute2= value2... attributen= valuen %>

********************************************************************

Component Based Software Engineering

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Servlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet.

COMP201 Java Programming

Session 8. Introduction to Servlets. Semester Project

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

Web based Applications, Tomcat and Servlets - Lab 3 -

CS506 Web Design & Development Final Term Solved MCQs with Reference

ADVANCED JAVA COURSE CURRICULUM

Scheme G Sample Question Paper Unit Test 2

Introduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web

Integrating Servlets and JavaServer Pages Lecture 13

Java Server Pages. JSP Part II

Actual4Test. Actual4test - actual test exam dumps-pass for IT exams

Transcription:

Java Server Pages JSP

Agenda Introduction JSP Architecture Scripting Elements Directives Implicit Objects 2

A way to create dynamic web pages Introduction Separates the graphical design from the dynamic content A JSP page is a text document that contains: Static data (such as HTML, WML, and XML) JSP elements, which construct dynamic content. 3

First Look at Code <html> <body> I am HTML code. <br> <b><% out.println("i am JSP Code"); %></b><br> <b><% out.println("today date & time is: "+java.time.localdatetime.now()); %></b> </body> </html> 4

Processing SRC:https://www.tutorialspoint.com/jsp/jsp_architecture.htm 5

Life Cycle SRC: https://www.tutorialspoint.com/jsp/jsp_life_cycle.htm 6

JSP/Servlet Correspondence Original JSP <%= printme() %> <% callme(); %> Possible resulting servlet code public void _jspservice(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { request.setcontenttype("text/html"); HttpSession session = request.getsession(true); JspWriter out = response.getwriter(); out.println(printme()); callme();... } 7

API Packages javax.servlet.jsp javax.servlet.jsp.tagext javax.servlet.jsp package Interfaces JspPage HttpJspPage Classes JspWriter PageContext JspFactory JspEngineInfo JspException JspError 8

Components Scripting Elements Directives Implicit Objects Actions 9

Scripting Elements Provides the ability to insert java code inside the jsp Three forms: Expressions of the form <%= expression %> that are evaluated and inserted into the output Scriptlets of the form <% code %> that are inserted into the servlet's service method Declarations of the form <%! code %> that are inserted into the body of the servlet class, outside of any existing methods. 10

Expression <% = expression %> <jsp:expression> expression </jsp:expression> Example: <%= java.time.localdate.now() %> 11

Scriptlet <% code fragment %> <jsp:scriptlet> code fragment </jsp:scriptlet> Example: <% out.println("your IP address is " + request.getremoteaddr()); %> 12

Declaration <%! declaration; %> <jsp:declaration> code fragment </jsp:declaration> <%! int i = 0; %> <%! int i; %> <%! Student student = new Student(); %> <%! int area(int a, int b){ return a*b; } %> 13

Example: Math.html <form method="post" action="math.jsp"> <input type="radio" name= operator" value="add" checked>addition<br> <input type="radio" name= operator" value= subtract" >Subtraction<br> <input type="radio" name= operator" value="multiply" >Multiplication<br> <input type="radio" name="operator" value="divide" >Division<br> <br><br> Enter first Value <input type="text" name= input1" value=""><br> Enter second Value <input type="text" name= input2" value=""><br> <input type="submit" name="result"> </form> 14

Example: Math.jsp <body> <%!int number1, number2, result;%> <H1> Result for <%=request.getparameter("operator")%></h1> <% number1 = Integer.parseInt(request.getParameter("input1")); number2 = Integer.parseInt(request.getParameter("input2")); result = 0; String str = request.getparameter("operator"); if (str.equals("add")) { result = number1 + number2; } if (str.equals("subtract")) { result = number1 - number2; } if (str.equals("multiply")) { result = number1 * number2; } if (str.equals("divide")) { result = number1 / number2; } %> Result is <%=result%> </body> 15

Directives Affects the overall structure of the servlet class Tells the web container how to translate a JSP page into the corresponding servlet. <%@ directive attribute="value" %> <%@ page... %> Defines attributes that apply to an entire JSP page. <%@ include... %> Includes a file during the translation phase. <%@ taglib... %> Declares a tag library, containing custom actions, used in the page 16

Page Directive <%@ page attribute="value" %> <jsp:directive.page attribute="value" /> Example: <%@ page extends= myclass import= java.util.* contenttype= text/html errorpage= error.jsp %> 17

Page directive Directives Values Description Language scriptinglanguage The default value is "java". Extends classname Import importlist java.lang.*, javax.servlet.*, javax.servlet.jsp.*, and javax.servlet.http.* are imported implicitily Session true false Buffer none sizekb Default 8 kb autoflush true false isthreadsafe true false Info info_text retrieved later by using getservletinfo() method errorpage iserrorpage contenttype pageencoding error_url true false contentinfo pageencodinginfo 18

errorpage & iserrorpage Authenticate.html Authenticate.jsp <%@ page errorpage="loginerrorpage.jsp" %> LoginErrorPage.jsp <%@ page iserrorpage="true" %> 19

Include Directive Includes a static file <%@ include file="relative url" > <jsp:directive.include file="relative url" /> Example: main.jsp: Current date and time is: <%@include file= date.jsp date.jsp: <%@page import = java.util.* %> <% =(new java.util.date()).tolocalestring() %> 20

Implicit Objects Object Description request This is the HttpServletRequest object associated with the request. response This is the HttpServletResponse object associated with the response to the client. out session application config pagecontext This is the PrintWriter object used to send output to the client. This is the HttpSession object associated with the request. This is the ServletContext object associated with application context. This is the ServletConfig object associated with the page. This encapsulates use of server-specific features like higher performance JspWriters. page Exception This is simply a synonym for this, and is used to call the methods defined by the translated servlet class. The Exception object allows the exception data to be accessed by designated JSP. 21

References https://docs.oracle.com/javaee/5/tutorial/doc/bnagx.html https://www.javatpoint.com/jsp-tutorial 22

Thank you 23