Sub: Advance Java Programming Laboratory
|
|
- Dustin Francis
- 6 years ago
- Views:
Transcription
1 1. Write a JAVA Servlet program to implement a dynamic HTML, using the servlet. (user name and password should be accepted using HTML and displayed using a Servlet) /**************** HTML CODE ******************/ //Pro_1.html <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools Templates and open the template in the editor. --> <html> <body bgcolor=aabbcc> <form action=pro_1 method="post"> NAME:<input type="text" name="name"><br> PASSWORD:<input type="password" name="pwd"><br> <input type="submit"> <input type="reset"> </form> </body> </html> /**************** Servlet Program Code ******************/ // Pro_1.java import javax.servlet.*; import java.io.*; public class Pro_1 extends GenericServlet public void service(servletrequest req, ServletResponse res) try PrintWriter pw=res.getwriter(); res.setcontenttype("text/html"); String name=req.getparameter("name"); String pwd=req.getparameter("pwd"); pw.println("<html><b>name:"+name+"<br>password:"+pwd+"</html>"); pw.close(); catch(exception excep) System.out.println(excep.getMessage()); Dept of MCA. KLEIT Hubli Page 1
2 Note: add Tomacats common- lib- servlet-api into Jcreator Note: Save the above servlet in the C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\WEB- INF\classes\Program1.java Save the file name as 8prog.html in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\2prog.html OUTPUT Open Internet Explorer and type the following URL Dept of MCA. KLEIT Hubli Page 2
3 Dept of MCA. KLEIT Hubli Page 3
4 2. Write a JAVA Servlet Program to Auto Web Page Refresh (Consider a webpage which is displaying Date and time or stock market status. For all such type of pages, you would need to refresh your web page regularly; Java Servlet makes this job easy by providing refresh automatically after a given interval). // Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; // Extend HttpServlet class public class LabProgram2 extends HttpServlet // Method to handle GET method request. public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException,IOException // Set refresh, autoload time as 5 seconds response.setintheader("refresh",5); // Set response content type response.setcontenttype("text/html"); // Get current time Calendar calendar =new GregorianCalendar(); String am_pm; int hour = calendar.get(calendar.hour); int minute = calendar.get(calendar.minute); int second = calendar.get(calendar.second); if(calendar.get(calendar.am_pm)==0) am_pm ="AM"; else am_pm ="PM"; String CT = hour+":"+ minute +":"+ second +" "+ am_pm; PrintWriter out= response.getwriter(); String title ="Auto Page Refresh using Servlet"; String doctype = "<!doctype html public \"-//w3c//dtd html 4.0 "+ "transitional//en\">\n"; out.println(doctype + "<html>\n"+ "<head><title>"+ title +"</title></head>\n"+ "<body bgcolor=\"#f0f0f0\">\n"+ "<h1 align=\"center\">"+ title +"</h1>\n"+ Dept of MCA. KLEIT Hubli Page 4
5 "<p>current Time is: "+ CT +"</p>\n"); // Method to handle POST method request. public void dopost(httpservletrequest request,httpservletresponse response) throws ServletException,IOException doget(request, response); Out Put : Dept of MCA. KLEIT Hubli Page 5
6 3. Write a JAVA Servlet Program to implement and demonstrate get() and Post methods(using HTTP Servlet Class). index.html <html> <body> <form action="helloform" method="get"> First Name: <input type="text" name="first_name"> <br/> Last Name: <input type="text" name="last_name"/> <input type="submit" value="submit"/> </form> </body> </html> HelloForm.java // Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; // Extend HttpServlet class public class HelloForm extends HttpServlet public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException,IOException // Set response content type response.setcontenttype("text/html"); PrintWriter out= response.getwriter(); String title ="Using GET Method to Read Form Data"; String doctype = "<!doctype html public \"-//w3c//dtd html 4.0 "+ "transitional//en\">\n"; out.println(doctype + "<html>\n"+ "<head><title>"+ title +"</title></head>\n"+ "<body bgcolor=\"#f0f0f0\">\n"+ "<h1 align=\"center\">"+ title +"</h1>\n"+ "<ul>\n"+ " <li><b>first Name</b>: " + request.getparameter("first_name")+"\n"+ " <li><b>last Name</b>: " + request.getparameter("last_name")+"\n"+ "</ul>\n"+ "</body></html>"); Dept of MCA. KLEIT Hubli Page 6
7 index2.html <html> <body> <form action="helloform2" method="post"> First Name: <input type="text" name="first_name"> <br/> Last Name: <input type="text" name="last_name"/> <input type="submit" value="submit"/> </form> </body> </html> HelloForm2.java // Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; // Extend HttpServlet class public class HelloForm2 extends HttpServlet // Method to handle GET method request. public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException,IOException // Set response content type response.setcontenttype("text/html"); PrintWriter out= response.getwriter(); String title ="Using Post Method to Read Form Data"; String doctype = "<!doctype html public \"-//w3c//dtd html 4.0 "+ "transitional//en\">\n"; out.println(doctype + "<html>\n"+ "<head><title>"+ title +"</title></head>\n"+ "<body bgcolor=\"#f0f0f0\">\n"+ "<h1 align=\"center\">"+ title +"</h1>\n"+ "<ul>\n"+ " <li><b>first Name</b>: " + request.getparameter("first_name")+"\n"+ " <li><b>last Name</b>: " + request.getparameter("last_name")+"\n"+ "</ul>\n"+ "</body></html>"); // Method to handle POST method request. public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException,IOException Dept of MCA. KLEIT Hubli Page 7
8 doget(request, response); Out Put: Using GET Method Dept of MCA. KLEIT Hubli Page 8
9 Dept of MCA. KLEIT Hubli Page 9
10 Using POST Method Dept of MCA. KLEIT Hubli Page 10
11 Dept of MCA. KLEIT Hubli Page 11
12 4. Write a JAVA Servlet Program using cookies to remember user preferences. ///************** First Program for storing Cookies ***************/// CookieUtilities.java import javax.servlet.http.*; /** Two static methods for use in cookie handling. */ public class CookieUtilities public static String getcookievalue(httpservletrequest request, String cookiename, String defaultvalue) Cookie[] cookies = request.getcookies(); if (cookies!= null) for (Cookie cookie : cookies) if (cookiename.equals(cookie.getname())) return(cookie.getvalue()); return(defaultvalue); public static Cookie getcookie(httpservletrequest request, String cookiename) Cookie[] cookies = request.getcookies(); if (cookies!= null) for (Cookie cookie : cookies) if (cookiename.equals(cookie.getname())) return(cookie); return(null); ///*************Second Program for Long Lived Cookie Initialization *****************/// LongLivedCookie.java import javax.servlet.http.*; Dept of MCA. KLEIT Hubli Page 12
13 /** Cookie that persists 1 year. Default Cookie doesn't * persist past current browsing session. */ public class LongLivedCookie extends Cookie public static final int SECONDS_PER_YEAR = 60*60*24*365; public LongLivedCookie(String name, String value) super(name, value); setmaxage(seconds_per_year); ///*************Third Program Registration Form ***********************/// RegistrationForm.java import javax.servlet.http.*; /** Cookie that persists 1 year. Default Cookie doesn't * persist past current browsing session. */ public class LongLivedCookie extends Cookie public static final int SECONDS_PER_YEAR = 60*60*24*365; public LongLivedCookie(String name, String value) super(name, value); setmaxage(seconds_per_year); ///********************** Registration Servlets ********************/// RegistrationServlet.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Servlet that processes a registration form containing * a user's first name, last name, and address. * If all the values are present, the servlet displays the * values. If any of the values are missing, the input * form is redisplayed. Either way, the values are put * into cookies so that the input form can use the * previous values. */ public class RegistrationServlet extends HttpServlet Dept of MCA. KLEIT Hubli Page 13
14 public void doget(httpservletrequest request,httpservletresponse response) throws ServletException, IOException response.setcontenttype("text/html"); boolean ismissingvalue = false; String firstname = request.getparameter("firstname"); if (ismissing(firstname)) firstname = "Missing first name"; ismissingvalue = true; String lastname = request.getparameter("lastname"); if (ismissing(lastname)) lastname = "Missing last name"; ismissingvalue = true; String address = request.getparameter(" address"); if (ismissing( address)) address = "Missing address"; ismissingvalue = true; Cookie c1 = new LongLivedCookie("firstName", firstname); response.addcookie(c1); Cookie c2 = new LongLivedCookie("lastName", lastname); response.addcookie(c2); Cookie c3 = new LongLivedCookie(" Address", Address); response.addcookie(c3); String formaddress = "/labprogram4/registrationform"; if (ismissingvalue) response.sendredirect(formaddress); else PrintWriter out = response.getwriter(); String doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; String title = "Thanks for Registering"; out.println (doctype + "<HTML>\n" + "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<CENTER>\n" + "<H1 ALIGN>" + title + "</H1>\n" + "<UL>\n" + " <LI><B>First Name</B>: " + firstname + "\n" + Dept of MCA. KLEIT Hubli Page 14
15 " <LI><B>Last Name</B>: " + lastname + "\n" + " <LI><B> address</b>: " + address + "\n" + "</UL>\n" + "</CENTER></BODY></HTML>"); /** Determines if value is null or empty. */ private boolean ismissing(string param) return((param == null) (param.trim().equals(""))); OutPut: Dept of MCA. KLEIT Hubli Page 15
16 Intermediate Page if I miss any Values: Dept of MCA. KLEIT Hubli Page 16
17 Final Page : Dept of MCA. KLEIT Hubli Page 17
18 Close the Session And Reopen It opens the page with Last Session information As shown Below: Dept of MCA. KLEIT Hubli Page 18
19 Dept of MCA. KLEIT Hubli Page 19
20 5. a. Write a JAVA JSP Program to implement verification of a particular user login and display a Welcome page. b. Write a JSP program to demonstrate the import attribute. 5a.jsp <html> <head> </head> <body> <% String s=request.getparameter("uname"); String s1=request.getparameter("pwd"); int temp=integer.parseint(s1); if(s.equals("pnt")&& temp==564) %> <p style="font size:30pt;align:center"><b>welcome to Web Page!!!<%=s %><b> <% else %>invalid password or invalid username <% %></body></html> Note: Save the File in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jspexamples\8b.jsp 5a.html <html> <head> <title>open page</title> <body> <form method="get" action="5a.jsp"> Username:<input type="text" name="uname"><br/> Password:<input type="password" name="pwd"><br/> <input type="submit" value="login"> <input type="reset" value="reset"> </form> </body> </html> Dept of MCA. KLEIT Hubli Page 20
21 Note: Save the File in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jspexamples\8b.html Output Open Internet Explorer and type the following URL Dept of MCA. KLEIT Hubli Page 21
22 Dept of MCA. KLEIT Hubli Page 22
23 6. Write a JAVA JSP Program which uses jsp:include and jsp:forward action to display a Webpage. //jsp:include Following is the content of date.jsp file: <p> Today's date: <%= (new java.util.date()).tolocalestring()%> </p> Here is the content of main.jsp file: <html> <head> <title>the include Action Example</title> </head> <body> <center> <h2>the include action Example</h2> <jsp:include page="date.jsp" flush="true" /> </center> </body> </html> Now let us keep all these files in root directory and try to access main.jsp. This would display result something like this: //jsp:forward Let us reuse following two files (a) date.jps and (b) main.jsp as follows: Following is the content of date.jsp file: <p> Today's date: <%= (new java.util.date()).tolocalestring()%> </p> Here is the content of main.jsp file: <html> <head> <title>the include Action Example</title> </head> <body> <center> <h2>the include action Example</h2> <jsp:forward page="date.jsp" /> </center> </body> </html> Now let us keep all these files in root directory and try to access main.jsp. This would display result something like as below. Here it discarded content from main page and displayed content from forwarded page only. Today's date: 12-Sep :54:22 Dept of MCA. KLEIT Hubli Page 23
24 7. Write a JAVA JSP Program which uses <jsp:plugin> tag to run a applet. Plugin.jsp <html> <title>plugin example</title> <body bgcolor="white"> <jsp:plugin type="applet" code="test.class" codebase="applet" jreversion="1.2" width="160" height="150"> <jsp:fallback> Plugin tag OBJECT or EMBED not supported by browser </jsp:fallback> </jsp:plugin> <p> <h4> <font color=red> The above applet is nloaded using the java Plugin from a jsp using the plugin tag </font> </h4> </body> </html> Note: create a folder in jsp-examples/kish/plugin.jsp import java.applet.*; import java.awt.graphics; public class Test extends Applet public void init() public void paint(graphics g) g.drawstring("kleit",10,10); public void start() public void stop() public void run() Dept of MCA. KLEIT Hubli Page 24
25 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jspexamples\mca\plugin.jsp OUTPUT Dept of MCA. KLEIT Hubli Page 25
26 8. Write a JAVA JSP Program to get student information through a HTML and create a JAVA Bean class, populate Bean and display the same information through another JSP. package beans; import java.io.serializable; public class Student implements Serializable String name=""; String =""; int age=0; public Student() public void SetName(String str) name=str; public String getname() return name; public void set (string str) =str; public String get () return ; public void setage(int str) age=str; public int getage() return age; Note: Save the Student.java in Dept of MCA. KLEIT Hubli Page 26
27 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\ Student.java <html> <head> </head> <body bgcolor="pink"> <h2> Student Details</h2> <hr/> language="java %> <jsp:usebean id="std" scope="session" class="beans.student"/> <% std.setname(request.getparameter("sname")); std.set (request.getparameter(" ")); std.setage(integer.parseint(request.getparameter("age"))); %> Student Name<%=std.getName()%> <br> <%=std.get ()%> <br> Age<%=std.getAge()%> </body> </html> Note: Save the File in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jspexamples\Student.jsp <html> <body> <form action ="Student.jsp"> StudentName<input type="text" name="sname"><br> ID<input type="text" name=" "><br> Age<input type="text" name="age"> <input type="submit"> </form> </body> </html> Note: Save the File in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jspexamples\Student.html Output Dept of MCA. KLEIT Hubli Page 27
28 Dept of MCA. KLEIT Hubli Page 28
29 9. Write a JAVA Program to insert data into Student DATA BASE and retrieve info based on particular queries(for example update, delete, search etc ). import java.sql.*; import java.io.*; public class JDBCExample static final String JDBC_DRIVER = "com.mysql.jdbc.driver"; static final String DB_URL = "jdbc:mysql://localhost/students"; static final String USER = "root"; static final String PASS = ""; public static void main(string[] args) BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Connection conn = null; Statement stmt = null; try Class.forName( com.mysql.jdbc.driver ); System.out.println("Connecting to a selected database..."); conn = DriverManager.getConnection(= "jdbc:mysql://localhost/students", root, ); System.out.println("Connected database successfully..."); System.out.println("Creating table in given database..."); stmt = conn.createstatement(); int ch; String sql; System.out.println("1. Create \n 2. Insert \n 3. Select \n 4. Drop \n 5. Exit"); System.out.println("Enter ur choice"); ch=integer.parseint(br.readline()); switch(ch) case 1: sql = "CREATE TABLE Temp" + "(id INTEGER not NULL, " + " first VARCHAR(255), " + Dept of MCA. KLEIT Hubli Page 29
30 break; case 2: " last VARCHAR(255), " + " age INTEGER, " + " PRIMARY KEY ( id ))"; stmt.executeupdate(sql); System.out.println("Created table in given database..."); System.out.println("Enter the id"); int id1= Integer.parseInt(br.readLine()); System.out.println("Enter the first name"); String fname=br.readline(); System.out.println("Enter the last name"); String lname=br.readline(); System.out.println("Enter the age"); String agee=br.readline(); sql = "insert into temp values ('"+id1+"','"+fname+"','"+lname+"','"+agee+"')"; break; case 3: stmt.executeupdate(sql); sql = "SELECT id, first, last, age FROM Temp"; ResultSet rs = stmt.executequery(sql); while(rs.next()) //Retrieve by column name int id = rs.getint("id"); int age = rs.getint("age"); String first = rs.getstring("first"); String last = rs.getstring("last"); //Display values System.out.print("ID: " + id); System.out.print(", Age: " + age); System.out.print(", First: " + first); System.out.println(", Last: " + last); rs.close(); break; case 4: sql="drop table Temp"; stmt.executeupdate(sql); System.out.println("Droppped table..."); Dept of MCA. KLEIT Hubli Page 30
31 break; catch(sqlexception se) //Handle errors for JDBC se.printstacktrace(); catch(exception e) //Handle errors for Class.forName e.printstacktrace(); finally //finally block used to close resources try if(stmt!=null) conn.close(); catch(sqlexception se) // do nothing try if(conn!=null) conn.close(); catch(sqlexception se) se.printstacktrace(); //end finally try //end try System.out.println("Goodbye!"); //end main //end JDBCExample Dept of MCA. KLEIT Hubli Page 31
32 OUTPUT:- Connecting to a selected database... Connected database successfully... Creating table in given database Create 2. Insert 3. Select 4. Drop 5. Exit Enter ur choice 3 ID: 100, Age: 20, First: vyas, Last: j ID: 101, Age: 25, First: bheem, Last: rao Goodbye! Press any key to continue... Dept of MCA. KLEIT Hubli Page 32
Handling Cookies. Agenda
Handling Cookies 1 Agenda Understanding the benefits and drawbacks of cookies Sending outgoing cookies Receiving incoming cookies Tracking repeat visitors Specifying cookie attributes Differentiating between
More informationHandling Cookies. For live Java EE training, please see training courses at
Edited with the trial version of 2012 Marty To Hall remove this notice, visit: Handling Cookies Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html
More informationJava Database Connectivity (JDBC) 25.1 What is JDBC?
PART 25 Java Database Connectivity (JDBC) 25.1 What is JDBC? JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java programming
More informationChettinad College of Engineering and Technology CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY
CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY UNIT IV SERVLETS 1. What is Servlets? a. Servlets are server side components that provide a powerful mechanism
More informationJSP - ACTIONS. There is only one syntax for the Action element, as it conforms to the XML standard:
http://www.tutorialspoint.com/jsp/jsp_actions.htm JSP - ACTIONS Copyright tutorialspoint.com JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically
More informationWHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD
W HI TEPAPER www. p rogres s.com WHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD In this whitepaper, we describe how to white label Progress Rollbase private cloud with your brand name by following a
More informationEXPERIMENT- 9. Login.html
EXPERIMENT- 9 To write a program that takes a name as input and on submit it shows a hello page with name taken from the request. And it shows starting time at the right top corner of the page and provides
More informationUnit-4: Servlet Sessions:
4.1 What Is Session Tracking? Unit-4: Servlet Sessions: Session tracking is the capability of a server to maintain the current state of a single client s sequential requests. Session simply means a particular
More informationAJP. CHAPTER 5: SERVLET -20 marks
1) Draw and explain the life cycle of servlet. (Explanation 3 Marks, Diagram -1 Marks) AJP CHAPTER 5: SERVLET -20 marks Ans : Three methods are central to the life cycle of a servlet. These are init( ),
More informationServlet Basics. Agenda
Servlet Basics 1 Agenda The basic structure of servlets A simple servlet that generates plain text A servlet that generates HTML Servlets and packages Some utilities that help build HTML The servlet life
More informationIntroduction. This course Software Architecture with Java will discuss the following topics:
Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations
More informationTopic 12: Database Programming using JDBC. Database & DBMS SQL JDBC
Topic 12: Database Programming using JDBC Database & DBMS SQL JDBC Database A database is an integrated collection of logically related records or files consolidated into a common pool that provides data
More informationIntroduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003
Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations
More informationServlet and JSP Review
2006 Marty Hall Servlet and JSP Review A Recap of the Basics 2 JSP, Servlet, Struts, JSF, AJAX, & Java 5 Training: http://courses.coreservlets.com J2EE Books from Sun Press: http://www.coreservlets.com
More information2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR
Installing a Web Server 1. Install a sample web server, which supports Servlets/JSPs. A light weight web server is Apache Tomcat server. You can get the server from http://tomcat.apache.org/ 2. Follow
More informationJdbcResultSet.java. import java.sql.*;
1)Write a program to display the current contents of the tables in the database where table name is Registration and attributes are id,firstname,lastname,age. JdbcResultSet.java import java.sql.*; public
More informationModule 4: SERVLET and JSP
1.What Is a Servlet? Module 4: SERVLET and JSP A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the Hyper
More informationKamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session
Kamnoetvidya Science Academy Object Oriented Programming using Java Ferdin Joe John Joseph Java Session Create the files as required in the below code and try using sessions in java servlets web.xml
More informationJava Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1
Java Enterprise Edition Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1 Java Beans Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 2 Java Bean POJO class : private Attributes public
More informationBackend. (Very) Simple server examples
Backend (Very) Simple server examples Web server example Browser HTML form HTTP/GET Webserver / Servlet JDBC DB Student example sqlite>.schema CREATE TABLE students(id integer primary key asc,name varchar(30));
More informationWeb based Applications, Tomcat and Servlets - Lab 3 -
CMPUT 391 Database Management Systems Web based Applications, - - CMPUT 391 Database Management Systems Department of Computing Science University of Alberta The Basic Web Server CMPUT 391 Database Management
More informationServlet 5.1 JDBC 5.2 JDBC
5 Servlet Java 5.1 JDBC JDBC Java DataBase Connectivity Java API JDBC Java Oracle, PostgreSQL, MySQL Java JDBC Servlet OpenOffice.org ver. 2.0 HSQLDB HSQLDB 100% Java HSQLDB SQL 5.2 JDBC Java 1. JDBC 2.
More informationUNIT-VI. HttpServletResponse It extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.
UNIT-VI javax.servlet.http package: The javax.servlet.http package contains a number of classes and interfaces that describe and define the contracts between a Servlet class running under the HTTP protocol
More informationJava4570: Session Tracking using Cookies *
OpenStax-CNX module: m48571 1 Java4570: Session Tracking using Cookies * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract
More informationJavaServer Pages (JSP)
JavaServer Pages (JSP) The Context The Presentation Layer of a Web App the graphical (web) user interface frequent design changes usually, dynamically generated HTML pages Should we use servlets? No difficult
More informationAdvanced Internet Technology Lab # 5 Handling Client Requests
Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Advanced Internet Technology Lab # 5 Handling Client Requests Eng. Doaa Abu Jabal Advanced Internet Technology Lab
More informationDEZVOLTAREA APLICATIILOR WEB LAB 4. Lect. Univ. Dr. Mihai Stancu
DEZVOLTAREA APLICATIILOR WEB LAB 4 Lect. Univ. Dr. Mihai Stancu J S P O v e r v i e w JSP Architecture J S P L i f e C y c l e Compilation Parsing the JSP. Turning the JSP into a servlet. Compiling the
More informationChapter 2 How to structure a web application with the MVC pattern
Chapter 2 How to structure a web application with the MVC pattern Murach's Java Servlets/JSP (3rd Ed.), C2 2014, Mike Murach & Associates, Inc. Slide 1 Objectives Knowledge 1. Describe the Model 1 pattern.
More informationCE212 Web Application Programming Part 3
CE212 Web Application Programming Part 3 30/01/2018 CE212 Part 4 1 Servlets 1 A servlet is a Java program running in a server engine containing methods that respond to requests from browsers by generating
More informationJava Server Pages. JSP Part II
Java Server Pages JSP Part II Agenda Actions Beans JSP & JDBC MVC 2 Components Scripting Elements Directives Implicit Objects Actions 3 Actions Actions are XML-syntax tags used to control the servlet engine
More informationServlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet.
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.*;
More informationServlets by Example. Joe Howse 7 June 2011
Servlets by Example Joe Howse 7 June 2011 What is a servlet? A servlet is a Java application that receives HTTP requests as input and generates HTTP responses as output. As the name implies, it runs on
More informationHow to structure a web application with the MVC pattern
Objectives Chapter 2 How to structure a web application with the MVC pattern Knowledge 1. Describe the Model 1 pattern. 2. Describe the Model 2 (MVC) pattern 3. Explain how the MVC pattern can improve
More informationSWE642 Oct. 22, 2003
import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.arraylist; DataServlet.java /** * First servlet in a two servlet application. It is responsible
More informationC:/Users/zzaier/Documents/NetBeansProjects/WebApplication4/src/java/mainpackage/MainClass.java
package mainpackage; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import javax.ws.rs.core.context; import
More informationPrinciples and Techniques of DBMS 6 JSP & Servlet
Principles and Techniques of DBMS 6 JSP & Servlet Haopeng Chen REliable, INtelligent and Scalable Systems Group (REINS) Shanghai Jiao Tong University Shanghai, China http://reins.se.sjtu.edu.cn/~chenhp
More informationHandout 31 Web Design & Development
Lecture 31 Session Tracking We have discussed the importance of session tracking in the previous handout. Now, we ll discover the basic techniques used for session tracking. Cookies are one of these techniques
More informationa. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.
Answers 1. What is the super interface to all the JDBC Drivers, specify their fully qualified name? a. Java.sql.Driver i. JDBC-ODBC Driver ii. Java-Native API Driver iii. All Java Net Driver iv. Java Native
More informationServlets. An extension of a web server runs inside a servlet container
Servlets What is a servlet? An extension of a web server runs inside a servlet container A Java class derived from the HttpServlet class A controller in webapplications captures requests can forward requests
More information3. The pool should be added now. You can start Weblogic server and see if there s any error message.
CS 342 Software Engineering Lab: Weblogic server (w/ database pools) setup, Servlet, XMLC warming up Professor: David Wolber (wolber@usfca.edu), TA: Samson Yingfeng Su (ysu@cs.usfca.edu) Setup Weblogic
More informationForm Data trong Servlet
Form Data trong Servlet Bạn gặp phải nhiều tình huống mà cần truyền một số thông tin từ trình duyệt của bạn tới Web Server và sau đó tới chương trình backend của bạn. Trình duyệt sử dụng hai phương thức
More informationCIS 3952 [Part 2] Java Servlets and JSP tutorial
Java Servlets Example 1 (Plain Servlet) SERVLET CODE import java.io.ioexception; import java.io.printwriter; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet;
More informationINTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M
INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M EXPLANATION - 1.B HTML FORM CREATION - 2 M SERVLET CODE IN POST METHOD IMPORT STATEMENTS - CLASS NAME AND METHOD (POST) -
More informationAbout the Tutorial. Audience. Prerequisites. Copyright & Disclaimer
About the Tutorial JDBC API is a Java API that can access any kind of tabular data, especially data stored in a Relational Database. JDBC works with Java on a variety of platforms, such as Windows, Mac
More informationJAVA SERVLET. Server-side Programming PROGRAMMING
JAVA SERVLET Server-side Programming PROGRAMMING 1 AGENDA Passing Parameters Session Management Cookie Hidden Form URL Rewriting HttpSession 2 HTML FORMS Form data consists of name, value pairs Values
More informationCOMP9321 Web Application Engineering
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2411 1 Review:
More informationAdvanced Internet Technology Lab # 6
Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Advanced Internet Technology Lab # 6 JSP cookies Eng. Doaa Abu Jabal Advanced Internet Technology Lab # 6 JSP cookies
More information1.264 Lecture 15. Web development environments: JavaScript Java applets, servlets Java (J2EE) Active Server Pages
1.264 Lecture 15 Web development environments: JavaScript Java applets, servlets Java (J2EE) Active Server Pages Development environments XML, WSDL are documents SOAP is HTTP extension UDDI is a directory/registry
More informationJAVA SERVLET. Server-side Programming INTRODUCTION
JAVA SERVLET Server-side Programming INTRODUCTION 1 AGENDA Introduction Java Servlet Web/Application Server Servlet Life Cycle Web Application Life Cycle Servlet API Writing Servlet Program Summary 2 INTRODUCTION
More informationDatabase Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실
데이타베이스시스템연구실 Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실 Overview http://www.tutorialspoint.com/jsp/index.htm What is JavaServer Pages? JavaServer Pages (JSP) is a server-side programming
More informationCOMP9321 Web Application Engineering
COMP9321 Web Application Engineering Java Server Pages (JSP) Dr. Basem Suleiman Service Oriented Computing Group, CSE, UNSW Australia Semester 1, 2016, Week 3 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2442
More informationAccessing EJB in Web applications
Accessing EJB in Web applications 1. 2. 3. 4. Developing Web applications Accessing JDBC in Web applications To run this tutorial, as a minimum you will be required to have installed the following prerequisite
More informationPreview from Notesale.co.uk Page 21 of 162
import java.sql.*; public class FirstExample { // JDBC driver name and database URL static final String JDBC_DRIVER = "com.mysql.jdbc.driver"; static final String DB_URL = "jdbc:mysql://localhost/emp";
More informationServletConfig Interface
ServletConfig Interface Author : Rajat Categories : Advance Java An object of ServletConfig is created by the web container for each servlet. This object can be used to get configuration information from
More informationUniversité Antonine - Baabda
Université Antonine - Baabda Faculté d ingénieurs en Informatique, Multimédia, Systèmes, Réseaux et Télécommunications Applications mobiles (Pocket PC, etc ) Project: Manipulate School Database Préparé
More informationAdvanced Internet Technology Lab # 4 Servlets
Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Advanced Internet Technology Lab # 4 Servlets Eng. Doaa Abu Jabal Advanced Internet Technology Lab # 4 Servlets Objective:
More informationSession 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)
Session 8 JavaBeans 1 Reading Reading & Reference Head First Chapter 3 (MVC) Reference JavaBeans Tutorialdocs.oracle.com/javase/tutorial/javabeans/ 2 2/27/2013 1 Lecture Objectives Understand how the Model/View/Controller
More informationScheme G Sample Question Paper Unit Test 2
Scheme G Sample Question Paper Unit Test 2 Course Name: Computer Engineering Group Course Code: CO/CD/CM/CW/IF Semester: Sixth Subject Title: Advanced Java Programming Marks: 25 Marks 17625 ---------------------------------------------------------------------------------------------------------------------------
More information&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,
! "# # $! " &' ()!"#$$&$'(!!! ($) * + #!,)& - #-& +"- #!(-& #& #$.//0& -#-!& #-$$!& 1+#& 2-2" (3" 3 * * +, - -! #.// HttpServlet $ Servlet 2 $"!4)$5 #& 5 5 6! 0 -.// # 1 7 8 5 9 2 35-4 2 3+ -4 2 36-4 $
More informationIntroduction. This course Software Architecture with Java will discuss the following topics:
Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations
More informationSession 8. Introduction to Servlets. Semester Project
Session 8 Introduction to Servlets 1 Semester Project Reverse engineer a version of the Oracle site You will be validating form fields with Ajax calls to a server You will use multiple formats for the
More informationPreview from Notesale.co.uk Page 6 of 132
15. SERVLET HANDLING DATE... 80 Getting Current Date & Time... 81 Date Comparison... 82 Date Formatting using SimpleDateFormat... 82 Simple DateFormat Format Codes... 83 16. SERVLETS PAGE REDIRECTION...
More information( A ) 8. If the address of an array is stored in $value, how do you get the values of this array? (B) \$value (C) &$value (D) $$value
CS 665 Information Delivery on the Internet Final Exam - Name: Fall 2002 Part 1: (75 points - 3 points for each problem) ( A ) 1. What protocol is used by all Web communications transactions? (A) HTTP
More informationHandling the Client Request: HTTP Request Headers
Handling the Client Request: HTTP Request Headers 1 Agenda Reading HTTP request headers Building a table of all the request headers Understanding the various request headers Reducing download times by
More informationThe Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4
CMPUT 391 Database Management Systems The Basic Web based Applications, - - CMPUT 391 Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems
More informationCS506 Web Design & Development Final Term Solved MCQs with Reference
with Reference I am student in MCS (Virtual University of Pakistan). All the MCQs are solved by me. I followed the Moaaz pattern in Writing and Layout this document. Because many students are familiar
More informationUnit 4 - Servlet. Servlet. Advantage of Servlet
Servlet Servlet technology is used to create web application, resides at server side and generates dynamic web page. Before Servlet, CGI (Common Gateway Interface) was popular as a server-side programming
More informationM.Tech. CSE - I Yr I Semester (19)
M.Tech. CSE - I Yr I Semester - 2010-11 (19) //service public ServletConfig getservletconfig() return sc; public String getservletinfo() return "Guide - T.PoornaShekhar, M.Tech CS & CSE Coordinator - www.scce.ac.in";
More informationGetting started with Winstone. Minimal servlet container
Getting started with Winstone Minimal servlet container What is Winstone? Winstone is a small servlet container, consisting of a single JAR file. You can run Winstone on your computer using Java, and get
More informationUnit 3 - Java Data Base Connectivity
Two-Tier Database Design The two-tier is based on Client-Server architecture. The direct communication takes place between client and server. There is no mediator between client and server. Because of
More informationDEZVOLTAREA APLICATIILOR WEB CURS 7. Lect. Univ. Dr. Mihai Stancu
DEZVOLTAREA APLICATIILOR WEB CURS 7 Lect. Univ. Dr. Mihai Stancu S u p o r t d e c u r s suport (Beginning JSP, JSF and Tomcat) Capitolul 3 JSP Application Architectures DEZVOLTAREA APLICATIILOR WEB CURS
More informationJava servlets CSCI 470: Web Science Keith Vertanen Copyright 2013
Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013 Overview Dynamic web content genera2on (thus far) CGI Web server modules Server- side scrip2ng e.g. PHP, ASP, JSP Custom web server Java
More informationPARTIAL Final Exam Reference Packet
PARTIAL Final Exam Reference Packet (Note that some items here may be more pertinent than others; you'll need to be discerning.) Example 1 - St10CommonImportTop.jsp (with comments removed)
More informationSession 9. Introduction to Servlets. Lecture Objectives
Session 9 Introduction to Servlets Lecture Objectives Understand the foundations for client/server Web interactions Understand the servlet life cycle 2 10/11/2018 1 Reading & Reference Reading Use the
More informationTo follow the Deitel publishing program, sign-up now for the DEITEL BUZZ ON-
Ordering Information: Advanced Java 2 Platform How to Program View the complete Table of Contents Read the Preface Download the Code Examples To view all the Deitel products and services available, visit
More informationAdvanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans
University of New York, Tirana M.Sc. Computer Science Advanced Topics in Operating Systems Manual for Lab Practices Enterprise JavaBeans PART III A Web Banking Application with EJB and MySQL Development
More informationPES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II
PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II Subject Name: Advanced JAVA programming Subject Code: 13MCA42 Time: 11:30-01:00PM Max.Marks: 50M ----------------------------------------------------------------------------------------------------------------
More informationUnit 4 Java Server Pages
Q1. List and Explain various stages of JSP life cycle. Briefly give the function of each phase. Ans. 1. A JSP life cycle can be defined as the entire process from its creation till the destruction. 2.
More informationJAVA SERVLET. Server-side Programming ADVANCED FEATURES
JAVA SERVLET Server-side Programming ADVANCED FEATURES 1 AGENDA RequestDispacher SendRedirect ServletConfig ServletContext ServletFilter SingleThreadedModel Events and Listeners Servlets & Database 2 REQUESTDISPATCHER
More informationComponent Based Software Engineering
Component Based Software Engineering Masato Suzuki School of Information Science Japan Advanced Institute of Science and Technology 1 Schedule Mar. 10 13:30-15:00 : 09. Introduction and basic concepts
More informationServlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?
What are Servlets? Servlets1 Fatemeh Abbasinejad abbasine@cs.ucdavis.edu A program that runs on a web server acting as middle layer between requests coming from a web browser and databases or applications
More informationSERVLET AND JSP FILTERS
SERVLET AND JSP FILTERS FILTERS OVERVIEW Filter basics Accessing the servlet context Using initialization parameters Blocking responses Modifying responses FILTERS: OVERVIEW Associated with any number
More informationJava Server Pages JSP
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
More informationSession 21. Expression Languages. Reading. Java EE 7 Chapter 9 in the Tutorial. Session 21 Expression Languages 11/7/ Robert Kelly,
Session 21 Expression Languages 1 Reading Java EE 7 Chapter 9 in the Tutorial 2 11/7/2018 1 Lecture Objectives Understand how Expression Languages can simplify the integration of data with a view Know
More informationWelcome 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
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 Web Development With The Struts API Tom Janofsky Outline Background
More informationServlets and JSP (Java Server Pages)
Servlets and JSP (Java Server Pages) XML HTTP CGI Web usability Last Week Nan Niu (nn@cs.toronto.edu) CSC309 -- Fall 2008 2 Servlets Generic Java2EE API for invoking and connecting to mini-servers (lightweight,
More informationJava. Curs 2. Danciu Gabriel Mihail. Septembrie 2018
Java Curs 2 Danciu Gabriel Mihail Septembrie 2018 Cuprins Operatori Clase Pachete Prezentare java.lang Introducere în baze de date Operatori aritmetici Operatorii pe biţi Operatori pe biţi: exemplu class
More informationJ2EE Web Development 13/1/ Application Servers. Application Servers. Agenda. In the beginning, there was darkness and cold.
1. Application Servers J2EE Web Development In the beginning, there was darkness and cold. Then, mainframe terminals terminals Centralized, non-distributed Agenda Application servers What is J2EE? Main
More informationIntroduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web
Introduction to Java Servlets James Baldo Jr. SWE 432 Design and Implementation of Software for the Web Web Applications A web application uses enabling technologies to 1. make web site contents dynamic
More informationINTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature
INTRODUCTION TO SERVLETS AND WEB CONTAINERS Actions in Accord with All the Laws of Nature Web server vs web container Most commercial web applications use Apache proven architecture and free license. Tomcat
More informationStateless -Session Bean
Stateless -Session Bean Prepared by: A.Saleem Raja MCA.,M.Phil.,(M.Tech) Lecturer/MCA Chettinad College of Engineering and Technology-Karur E-Mail: asaleemrajasec@gmail.com Creating an Enterprise Application
More informationUnit III- Server Side Technologies
Web Technology Unit III- Server Side Technologies By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and not
More informationIntroduction. This course Software Architecture with Java will discuss the following topics.
Introduction This course Software Architecture with Java will discuss the following topics. I Java servlets I Java Server Pages (JSP's) I Java Beans I JDBC, connections to RDBMS and SQL I XML and XML translations
More informationICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.
Chapter 8: Application Design and Development ICOM 5016 Database Systems Web Application Amir H. Chinaei Department of Electrical and Computer Engineering University of Puerto Rico, Mayagüez User Interfaces
More informationCopyright 2005, by Object Computing, Inc. (OCI). All rights reserved. Database to Web
Database To Web 10-1 The Problem Need to present information in a database on web pages want access from any browser may require at least HTML 4 compatibility Want to separate gathering of data from formatting
More informationMARATHWADA INSTITUTE OF TECHNOLOGY, AURANGABAD DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS ADVANCE JAVA QUESTION BANK
MARATHWADA INSTITUTE OF TECHNOLOGY, AURANGABAD DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS ADVANCE JAVA QUESTION BANK Second Year MCA 2013-14 (Part-I) Faculties: Prof. V.V Shaga Prof. S.Samee Prof. A.P.Gosavi
More informationJSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP:
http://www.tutorialspoint.com/jsp/jsp_syntax.htm JSP - SYNTAX Copyright tutorialspoint.com This tutorial will give basic idea on simple syntax ie. elements involved with JSP development: The Scriptlet:
More informationAdvanced Web Technology
Berne University of Applied Sciences Dr. E. Benoist Winter Term 2005-2006 Presentation 1 Presentation of the Course Part Java and the Web Servlet JSP and JSP Deployment The Model View Controler (Java Server
More informationStateless Session Bean
Stateless Session Bean Stateful Session Bean Developing EJB applications Stateless beans are used in the case when the process or action can be completed in one go. In this case, object state will not
More informationChapter #1. Program to demonstrate applet life cycle
Chapter #1. Program to demonstrate applet life cycle import java.applet.applet; import java.awt.*; public class LifeCycle extends Applet{ public void init(){ System.out.println(" init()"); public void
More information