Introduction to Java Server Page (JSP) Yoshi. What is JSP JSPs have dynamic scripting capability that works in tandem with HTML code, separating the page.

Slides:



Advertisements
Similar presentations
Object-Oriented Enterprise Application Development JavaServer Pages.
Advertisements

CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer 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.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Java Server Pages by Jon Pearce. JSP Documents JSP docs are XHTML Documents containing: –Fixed-Template Data: FTD HTML Components XML markup –JSP Components:
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,
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.
Servlet and JSP Programming: An Introduction Spiros Papadimitriou
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
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.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Java Server Pages. JSP Documents JSP docs are XHTML Documents containing: –Fixed-Template Data: FTD HTML Components XML markup –JSP Components:
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Objectives Java Servlet Web Components
JSP Java Server Pages Softsmith Infotech.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
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.
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
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)
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Jsp (Java Server Page) Is a server side program.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
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.
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 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.
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.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
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.
INVOKING JAVA CODE WITH JSP SCRIPTING ELEMENTS. Creating Template Text A large percentage of your JSP document consists of static text (usually HTML),
Introduction To HTML Dr. Magdi AMER. HTML elements.
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.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 4 Request and Response. Servlets are controlled by the container.
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. Hello, !
Spell Checker web service (you build a web client that interacts with the service) The client uses a servlet class and a JSP page. The user passes information.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
JSP Implicit Objects CS 422 Dick Steflik.
Java Servlets By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
Pre-assessment Questions
Invoking Java Code from JSP
Objectives In this lesson you will learn about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
Introduction to Java Servlets
COSC 2956 Internet Tools Java Server Pages.
Presentation transcript:

Introduction to Java Server Page (JSP) Yoshi

What is JSP JSPs have dynamic scripting capability that works in tandem with HTML code, separating the page logic from the static elementsJSPs are compiled into Java Servlets by a JSP compiler. A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler Similar to PHP, ASP, ASP.NET, …etc For more information –

Four kinds of segments Declaration – For member level declaration Methods and fields – Scriptlet – _jspService() – Expression – Directive –

JSP is …

To servlet is … package jsp_servlet; import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import com.foo.bar; // Imported as a result of import …

To servlet is … (2) class _myservlet implements javax.servlet.Servlet, javax.servlet.jsp.HttpJspPage { // Inserted as a // result of int serverInstanceVariable = 1; … public void _jspService( javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response ) throws javax.servlet.ServletException, java.io.IOException { javax.servlet.ServletConfig config = …; // Get the servlet config

To servlet is … (3) Object page = this; // Get the page context for this request PageContext pageContext = …; javax.servlet.jsp.JspWriter out = pageContext.getOut(); HttpSession session = request.getSession( true ); try { out.print( " \r\n" ); … // From int localStackBasedVariable = 1; …

To servlet is … (4) out.print( " \r\n" ); out.print( " " ); // From out.print( toStringOrBlank( "expanded inline data " + 1 ) ); out.print( " \r\n" ); … } catch ( Exception _exception ) { // Clean up and redirect to error page in page // errorPage="myerror.jsp" %> }

Implicit Objects out – The JspWriter used to write the data to the response stream(output page).JspWriter page – The servlet itself. pageContext – A PageContext instance that contains data associated with the whole page. A given HTML page may be passed among multiple JSPs.PageContext request – The HttpServletRequest object that provides HTTP request information.HttpServletRequestHTTP request What are they in servlet?

Implicit Objects (2) response – The HttpServletResponse object that can be used to send data back to the client.HttpServletResponse session – The HttpSession object that can be used to track information about a user from one request to another.HttpSession config – Provides servlet configuration data. application – Data shared by all JSPs and servlets in the application. exception – Exceptions not caught by application code.

Get the Container An engine to compile/run your JSP/Servlet – Tomcat – Resin (We choose this one)

Resin Let’s run it – Test it by Browser with port You should see a default homepage – Do you have any idea to write a Web Application? If no now, let’s implement a fake lab3 now!

Directory structure

Let’s implement Lab3 resin-3.1.9\webapps\fakeLab3\upload.html Put BeanShell into resin-3.1.9\webapps\fakeLab3\WEB- INF\lib\bsh-core-2.0b4.jar – Why? – Check resin-3.1.9\conf\app-default.xml

upload.html Post your code:

uploadHandle.jsp <% synchronized(this) { String code = request.getParameter("code"); PrintStream originalOut = System.out; ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); PrintStream newStream = new PrintStream(outBuffer); System.setOut(newStream); System.setErr(newStream); Interpreter i = new Interpreter(); try { WHY?

uploadHandle.jsp i.eval(code); } catch(Exception e) { e.printStackTrace(); System.err.flush(); } System.out.flush(); out.println(outBuffer.toString()); System.setOut(originalOut); System.setErr(originalOut); } %>

Run! Let’s try it!

Discussions Compare with our Lab3, is it easier to achieve the goal? – Undoubtedly, yes! – But before we use it, we have to know some configurations inside the container Containers may follow the same standards, ideally Your application becomes “web application” Can you give more popular web applications? – Gmail, YouTube, Wretch, Pixnet, …etc – Can you write one for promoting NTHU?

Useful references t/JSPServlet.htm (Easy) t/JSPServlet.htm