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

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

ServletConfig Interface

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

Servlet Basics. Agenda

Advanced Internet Technology Lab # 4 Servlets

Advanced Web Technology

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

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

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

Servlet Fudamentals. Celsina Bignoli

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

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

Chettinad College of Engineering and Technology CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY

JAVA SERVLET. Server-side Programming INTRODUCTION

AJP. CHAPTER 5: SERVLET -20 marks

JavaServer Pages (JSP)

SERVLET AND JSP FILTERS

Session 8. Introduction to Servlets. Semester Project

Web based Applications, Tomcat and Servlets - Lab 3 -

Unit-4: Servlet Sessions:

Using Java servlets to generate dynamic WAP content

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

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

J2EE Web Development 13/1/ Application Servers. Application Servers. Agenda. In the beginning, there was darkness and cold.

Stateless -Session Bean

Java Servlets. Preparing your System

Getting started with Winstone. Minimal servlet container

A Servlet-Based Search Engine. Introduction

Introduction to Web applications with Java Technology 3- Servlets

Session 9. Introduction to Servlets. Lecture Objectives

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets

JAVA SERVLET. Server-side Programming PROGRAMMING

CIS 3952 [Part 2] Java Servlets and JSP tutorial

Handout 31 Web Design & Development

Servlets by Example. Joe Howse 7 June 2011

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

COMP9321 Web Application Engineering

Module 4: SERVLET and JSP

WHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD

Java4570: Session Tracking using Cookies *

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

JdbcResultSet.java. import java.sql.*;

Backend. (Very) Simple server examples

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

Advanced Internet Technology Lab # 5 Handling Client Requests

COMP9321 Web Application Engineering

Java TM. JavaServer Faces. Jaroslav Porubän 2008

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation

JAVA SERVLET. Server-side Programming ADVANCED FEATURES

To follow the Deitel publishing program, sign-up now for the DEITEL BUZZ ON-

CSC309: Introduction to Web Programming. Lecture 10

Chapter 17. Web-Application Development

Servlets and JSP (Java Server Pages)

Lecture Notes On J2EE

INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M

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

Get the cookies from the service request: Cookie[] HttpServletRequest.getCookies() Add a cookie to the service response:

Enterprise Java Unit 1- Chapter 4 Prof. Sujata Rizal Servlet API and Lifecycle

Introduction to Servlets. After which you will doget it

CS433 Technology Overview

SWE642 Oct. 22, 2003

Servlets Basic Operations

3. The pool should be added now. You can start Weblogic server and see if there s any error message.

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013

Unit III- Server Side Technologies

Unit 4 - Servlet. Servlet. Advantage of Servlet

Servlet 5.1 JDBC 5.2 JDBC

Principles and Techniques of DBMS 6 JSP & Servlet

JAVA. Web applications Servlets, JSP

Servlet. 1.1 Web. 1.2 Servlet. HTML CGI Common Gateway Interface Web CGI CGI. Java Applet JavaScript Web. Java CGI Servlet. Java. Apache Tomcat Jetty

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

Session 10. Form Dataset. Lecture Objectives

Kamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session

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

Fraud Detection And Integrity Of Database Without Using Pl-SQL Logic

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

HTTP status codes. Setting status of an HTTPServletResponse

HTTP. HTTP HTML Parsing. Java

First Servlets. Chapter. Topics in This Chapter

To create a view for students, staffs and courses in your departments using servlet/jsp.

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

Java Server Pages JSP

SDN Community Contribution

Distributed Systems Labs

Accessing EJB in Web applications

Welcome to Ruby. Yehuda Katz. Engine Yard

Handling Cookies. Agenda

Servlet for Json or CSV (or XML) A servlet serving either Json or CSV (or XML) based on GET parameter - This version uses org.json

Develop an Enterprise Java Bean for Banking Operations

Scheme G Sample Question Paper Unit Test 2

Chapter 2 How to structure a web application with the MVC pattern

Using the JBoss IDE for Eclipse

Server and WebLogic Express

Unit III- Server Side Technologies

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

Lab session Google Application Engine - GAE. Navid Nikaein

Server Side Internet Programming

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

Handling the Client Request: HTTP Request Headers

The Servlet as Client

Transcription:

Servlet OOS Lab

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

Servlet - Example OOS import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloClientServlet extends HttpServlet { protected void doget (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setcontenttype("text/html"); PrintWriter out = res.getwriter(); out.println("<html><head><title>hello Client!</TITLE>"+ "</HEAD><BODY>Hello Client!</BODY></HTML>"); out.close(); public String getservletinfo() { return SimpleServlet ; 3

Servlet For Dynamic Content OOS 4

Servlet For Dynamic Content OOS import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloClientServlet extends HttpServlet { protected void doget (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setcontenttype("text/html"); PrintWriter out = res.getwriter(); out.println("<html><head><title>hello Client!</TITLE>"+ "</HEAD><BODY>Hello Client!<P><HR> ) ; out.println( You are from + req.getremotehost() + : + req.getremoteport() + at + req.getrequesturl() ) ; out.println( </BODY></HTML>"); out.close(); public String getservletinfo() { return Simple Servlet with Dynamic Info. ; 5

Processing GET Request OOS GreetingServlet handles both pages http://localhost:8080/hello2/greeting?username=korea 6

public class GreetingServlet extends HttpServlet { public void doget ( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); response.setbuffersize(8192); PrintWriter out = response.getwriter(); out.println("<html>" + "<head><title>hello</title></head>"); out.println( "<body><img src=\"duke.waving.gif\" alt=\"duke waving\">" + "<h2>hello, my name is Duke. What's yours?</h2>" + "<form method=\"get\">" + "<input type=\"text\" name=\"username\" size=\"25\">" + "<p></p>" + "<input type=\"submit\" value=\"submit\">" + "<input type=\"reset\" value=\"reset\">" + "</form>"); String username = request.getparameter("username"); if ((username!= null) && (username.length() > 0)) { RequestDispatcher dispatcher = getservletcontext().getrequestdispatcher("/response"); if (dispatcher!= null) { dispatcher.include(request, response); out.println("</body></html>"); out.close(); public String getservletinfo() { return "The Hello servlet says hello.";

Form Processing Servlet OOS process form data manage persistent data use init parameters by Stefan Zeiger http://www.novocode.com/doc/servlet-essentials/ 8

import java.util.vector; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ListManagerServlet extends HttpServlet { private Vector addresses; private String filename; public void init(servletconfig config) throws ServletException { super.init(config); filename = config.getinitparameter("addressfile"); try { WEB-INF\web.xml ObjectInputStream in = new ObjectInputStream(new FileInputStream(filename)); addresses = (Vector)in.readObject(); in.close(); catch(ioexception e) { addresses = new Vector(); catch(classnotfoundexception e) {addresses = new Vector();

protected void doget(httpservletrequest req, HttpServletResponse res) throws ServletException, IOException 37: { res.setcontenttype("text/html"); res.setheader("pragma", "no-cache"); PrintWriter out = res.getwriter(); out.print("<html><head><title>list Manager</TITLE></HEAD>"); out.print("<body><h3>members:</h3><ul>"); for(int i=0; i<addresses.size(); i++) out.print("<li>" + addresses.elementat(i)); out.print("</ul><hr><form METHOD=POST>"); out.print("enter your email address: <INPUT TYPE=TEXT NAME=email><BR>"); out.print("<input TYPE=SUBMIT NAME=action VALUE=subscribe>"); out.print("<input TYPE=SUBMIT NAME=action VALUE=unsubscribe>"); out.print("</form></body></html>"); out.close();

protected void dopost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String email = req.getparameter("email"); String msg; if(email == null) { res.senderror(res.sc_bad_request, "No email address specified."); return; if(req.getparameter("action").equals("subscribe")) { if ( subscribe(email) ) msg = "Address " + email + " has been subscribed."; else { res.senderror(res.sc_bad_request, "Address " + email + " was already subscribed."); return; else { // unsubscribe is requested. if ( unsubscribe(email) ) msg = "Address " + email + " has been removed."; else { res.senderror(res.sc_bad_request, "Address " + email + " was not subscribed."); return; res.setcontenttype("text/html"); res.setheader("pragma", "no-cache"); PrintWriter out = res.getwriter(); out.print("<html><head><title>list Manager</TITLE></HEAD><BODY>"); out.print(msg); out.print("<hr><a HREF=\""); out.print(req.getrequesturi()); out.print("\">show the list</a></body></html>"); out.close(); public String getservletinfo() { return "ListManagerServlet 1.0 by Stefan Zeiger";

private synchronized boolean subscribe (String email) throws IOException { if ( addresses.contains(email) ) return false; addresses.addelement(email); save(); return true; private synchronized boolean unsubscribe (String email) throws IOException { if (!addresses.removeelement(email) ) return false; save(); return true; private void save() throws IOException { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename)); out.writeobject(addresses); out.close();