SlideShare a Scribd company logo
I
       •Servlets

 II
       •Java Server Pages (JSP)

III
       •Preparing the Dev. Enviornment

IV
       •Web-App Folders and Hierarchy

 V
       •Writing the First Servlet

VII
       •Compiling

VIII
       •Deploying a Sample Servlet (Packaged & Unpackaged)

VI
       •Writing the First JSP
   A servlet is a Java programming language class used to extend the
    capabilities of servers that host applications accessed via a request-
    response programming model

   A servlet is like any other java class

   Although servlets can respond to any type of request, they are
    commonly used to extend the applications hosted by Web servers
   Use regular HTML for most of page

   Mark dynamic content with special tags

   A JSP technically gets converted to a servlet but it looks more like
    PHP files where you embed the java into HTML.

   The character sequences <% and %> enclose Java expressions, which
    are evaluated at run time

                        <%= new java.util.Date() %>
   Java Development Kit (JDK)
    ◦ http://www.oracle.com/technetwork/java/javase/downloads/index.html


   Apache Tomcat webserver
    ◦ http://tomcat.apache.org/download-70.cgi


   Set JAVA_HOME Environmental Variable
    ◦   Right click on “Computer” (Win 7), and click on “Properties”
    ◦   Click on “Advanced System Settings” on top right corner
    ◦   On the new window opened click on “Environment Variables”
    ◦   In the “System Variables” section, the upper part of the window, click on “New…”
           Variable name: JAVA_HOME
           Variable value: Path to the jdk directory (in my case C:Program FilesJavajdk1.6.0_21)
    ◦ Click on “OK”
   Set CATALINA_HOME Environmental Variable
    ◦   Right click on “Computer” (Win 7), and click on “Properties”
    ◦   Click on “Advanced System Settings” on top right corner
    ◦   On the new window opened click on “Environment Variables”
    ◦   In the “System Variables” section, the upper part of the window, click on “New…”
           Variable name: CATALINA_HOME
           Variable value: Path to the apache-tomcat directory (in my case D:Serversapache-tomcat-
            7.0.12-windows-x86apache-tomcat-7.0.12)
    ◦ Click on “OK”


    Note: You might need to restart your computer after adding environmental variables to
                                make changes to take effect
   In your browser type: localhost:8080
    ◦ If tomcat’s page is opened then the webserver installation was successful




   Check JAVA_HOME variable:
    ◦ in command prompt type: echo %JAVA_HOME%
    ◦ Check to see the variable value and if it is set correctly
   All the content should be placed under tomcat’s “webapps” directory
• $CATALINA_HOMEwebappshelloservlet": This directory is known as context root for the web context
  "helloservlet". It contains the resources that are visible by the clients, such as HTML, CSS, Scripts and
  images. These resources will be delivered to the clients as it is. You could create sub-directories such as
  images, css and scripts, to further categories the resources accessible by clients.


• "$CATALINA_HOMEwebappshelloservletWEB-INF": This is a hidden directory that is used by the server.
  It is NOT accessible by the clients directly (for security reason). This is where you keep your application-
  specific configuration files such as "web.xml" (which we will elaborate later). It's sub-directories contain
  program classes, source files, and libraries.


• "$CATALINA_HOMEwebappshelloservletWEB-INFsrc": Keep the Java program source files. It is
  optional but a good practice to separate the source files and classes to facilitate deployment.


• "$CATALINA_HOMEwebappshelloservletWEB-INFclasses": Keep the Java classes (compiled from the
  source codes). Classes defined in packages must be kept according to the package directory structure.


• "$CATALINA_HOMEwebappshelloservletWEB-INFlib": keep the libraries (JAR-files), which are provided
  by other packages, available to this webapp only.
<HTML>
<HEAD>
<TITLE>Introductions</TITLE>
</HEAD>
<BODY>
<FORM METHOD=GET ACTION="/servlet/Hello">
If you don't mind me asking, what is your name?
<INPUT TYPE=TEXT NAME="name"><P>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Hello extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse res)
                      throws ServletException, IOException {

        res.setContentType("text/html");
        PrintWriter out = res.getWriter();

        String name = req.getParameter("name");
        out.println("<HTML>");
        out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("Hello, " + name);
        out.println("</BODY></HTML>");
    }

    public String getServletInfo() {
      return "A servlet that knows the name of the person to whom it's" +
           "saying hello";
    }
}
   The web.xml file
    defines each
    servlet and JSP      <?xml version="1.0" encoding="ISO-8859-1"?>
    page within a Web
    Application.         <!DOCTYPE web-app
                           PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
                           "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
   The file goes into
    the WEB-INF          <web-app>
    directory              <servlet>
                             <servlet-name>
                               hi
                             </servlet-name>
                             <servlet-class>
                               HelloWorld
                             </servlet-class>
                           </servlet>
                           <servlet-mapping>
                             <servlet-name>
                               hi
                             </servlet-name>
                             <url-pattern>
                               /hello.html
                             </url-pattern>
                           </servlet-mapping>
                         </web-app>
   Compile the packages:
    "C:Program FilesJavajdk1.6.0_17binjavac" <Package Name>*.java -d .


   If external (outside the current working directory) classes and
    libraries are used, we will need to explicitly define the CLASSPATH to
    list all the directories which contain used classes and libraries
    set CLASSPATH=C:libjarsclassifier.jar ;C:UserProfilingjarsprofiles.jar


   -d (directory)
    ◦ Set the destination directory for class files. The destination directory must
      already exist.
    ◦ If a class is part of a package, javac puts the class file in a subdirectory
      reflecting the package name, creating directories as needed.

   -classpath
    ◦ Set the user class path, overriding the user class path in the CLASSPATH environment
      variable.
    ◦ If neither CLASSPATH or -classpath is specified, the user class path consists of the
      current directory
                 java -classpath C:javaMyClasses utility.myapp.Cool
   What does the following command do?




    Javac –classpath .;..classes;”D:Serversapache-
    tomcat-6.0.26-windows-x86apache-tomcat-
    6.0.26libservlet-api.jar” src*.java –d ./test
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SimpleCounter extends HttpServlet {

    int count = 0;

    public void doGet(HttpServletRequest req, HttpServletResponse res)
                         throws ServletException, IOException {
      res.setContentType("text/plain");
      PrintWriter out = res.getWriter();
      count++;
      out.println("Since loading, this servlet has been accessed " +
              count + " times.");
    }
}
JSP
HTML
                                      <HTML>
<HTML>
                                      <BODY>
<BODY>
Hello, world                          Hello! The time is now <%= new java.util.Date() %>
</BODY>                               </BODY>
</HTML>                               </HTML>




                  Same as HTML, but just save it with .jsp extension
AUA – CoE
Apr.11, Spring 2012
1. Hashtable is synchronized, whereas HashMap is not.
    1. This makes HashMap better for non-threaded applications, as
       unsynchronized Objects typically perform better than synchronized ones.


2. Hashtable does not allow null keys or values. HashMap allows one null key and
   any number of null values.

More Related Content

What's hot

Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
Anand kalla
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
Aravindharamanan S
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Arun Gupta
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
deepak kumar
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cooljavablend
 
Mule esb
Mule esbMule esb
Mule esb
Khan625
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
Fahad Golra
 
jsp MySQL database connectivity
jsp MySQL database connectivityjsp MySQL database connectivity
jsp MySQL database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Maven
MavenMaven
Maven
javeed_mhd
 
Maven
MavenMaven
Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in mule
AnilKumar Etagowni
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 
Servlets
ServletsServlets
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
Fahad Golra
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaVasil Remeniuk
 

What's hot (20)

Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool
 
Mule esb
Mule esbMule esb
Mule esb
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
jsp MySQL database connectivity
jsp MySQL database connectivityjsp MySQL database connectivity
jsp MySQL database connectivity
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in mule
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
Servlets
ServletsServlets
Servlets
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
 

Viewers also liked

Ayb School Presentation
Ayb School PresentationAyb School Presentation
Ayb School Presentation
Ayb Educational Foundation, Vem Radio
 
Irt
IrtIrt
2006 Philippine eLearning Society National Conference
2006 Philippine eLearning Society National Conference2006 Philippine eLearning Society National Conference
2006 Philippine eLearning Society National Conference
Marie Casas
 
Learn How SMBs Are Cutting IT Costs By Over 50%
Learn How SMBs Are Cutting IT Costs By Over 50%Learn How SMBs Are Cutting IT Costs By Over 50%
Learn How SMBs Are Cutting IT Costs By Over 50%
Lunarpages Internet Solutions
 
Tect presentation classroom_based_technology_v2010-12-1
Tect presentation classroom_based_technology_v2010-12-1Tect presentation classroom_based_technology_v2010-12-1
Tect presentation classroom_based_technology_v2010-12-1esksaints
 
Tetc 2010 preso
Tetc 2010 presoTetc 2010 preso
Tetc 2010 presoesksaints
 

Viewers also liked (6)

Ayb School Presentation
Ayb School PresentationAyb School Presentation
Ayb School Presentation
 
Irt
IrtIrt
Irt
 
2006 Philippine eLearning Society National Conference
2006 Philippine eLearning Society National Conference2006 Philippine eLearning Society National Conference
2006 Philippine eLearning Society National Conference
 
Learn How SMBs Are Cutting IT Costs By Over 50%
Learn How SMBs Are Cutting IT Costs By Over 50%Learn How SMBs Are Cutting IT Costs By Over 50%
Learn How SMBs Are Cutting IT Costs By Over 50%
 
Tect presentation classroom_based_technology_v2010-12-1
Tect presentation classroom_based_technology_v2010-12-1Tect presentation classroom_based_technology_v2010-12-1
Tect presentation classroom_based_technology_v2010-12-1
 
Tetc 2010 preso
Tetc 2010 presoTetc 2010 preso
Tetc 2010 preso
 

Similar to Cis 274 intro

Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet examplervpprash
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and ServletsRaghu nath
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
Minal Maniar
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Auwal Amshi
 
Tomcat server
 Tomcat server Tomcat server
Tomcat server
Utkarsh Agarwal
 
18CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-318CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-3
sivakumarmcs
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
BG Java EE Course
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
01 web-apps
01 web-apps01 web-apps
01 web-appssnopteck
 
01 web-apps
01 web-apps01 web-apps
01 web-apps
Aravindharamanan S
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Arun Gupta
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
SachinSingh217687
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
Arun Gupta
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
Kaml Sah
 

Similar to Cis 274 intro (20)

Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Jdbc
JdbcJdbc
Jdbc
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Lect06 tomcat1
Lect06 tomcat1Lect06 tomcat1
Lect06 tomcat1
 
Tomcat server
 Tomcat server Tomcat server
Tomcat server
 
18CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-318CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-3
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
01 web-apps
01 web-apps01 web-apps
01 web-apps
 
01 web-apps
01 web-apps01 web-apps
01 web-apps
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
 
bjhbj
bjhbjbjhbj
bjhbj
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 

Cis 274 intro

  • 1.
  • 2. I •Servlets II •Java Server Pages (JSP) III •Preparing the Dev. Enviornment IV •Web-App Folders and Hierarchy V •Writing the First Servlet VII •Compiling VIII •Deploying a Sample Servlet (Packaged & Unpackaged) VI •Writing the First JSP
  • 3. A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed via a request- response programming model  A servlet is like any other java class  Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by Web servers
  • 4. Use regular HTML for most of page  Mark dynamic content with special tags  A JSP technically gets converted to a servlet but it looks more like PHP files where you embed the java into HTML.  The character sequences <% and %> enclose Java expressions, which are evaluated at run time <%= new java.util.Date() %>
  • 5.
  • 6. Java Development Kit (JDK) ◦ http://www.oracle.com/technetwork/java/javase/downloads/index.html  Apache Tomcat webserver ◦ http://tomcat.apache.org/download-70.cgi  Set JAVA_HOME Environmental Variable ◦ Right click on “Computer” (Win 7), and click on “Properties” ◦ Click on “Advanced System Settings” on top right corner ◦ On the new window opened click on “Environment Variables” ◦ In the “System Variables” section, the upper part of the window, click on “New…”  Variable name: JAVA_HOME  Variable value: Path to the jdk directory (in my case C:Program FilesJavajdk1.6.0_21) ◦ Click on “OK”
  • 7. Set CATALINA_HOME Environmental Variable ◦ Right click on “Computer” (Win 7), and click on “Properties” ◦ Click on “Advanced System Settings” on top right corner ◦ On the new window opened click on “Environment Variables” ◦ In the “System Variables” section, the upper part of the window, click on “New…”  Variable name: CATALINA_HOME  Variable value: Path to the apache-tomcat directory (in my case D:Serversapache-tomcat- 7.0.12-windows-x86apache-tomcat-7.0.12) ◦ Click on “OK” Note: You might need to restart your computer after adding environmental variables to make changes to take effect
  • 8. In your browser type: localhost:8080 ◦ If tomcat’s page is opened then the webserver installation was successful  Check JAVA_HOME variable: ◦ in command prompt type: echo %JAVA_HOME% ◦ Check to see the variable value and if it is set correctly
  • 9. All the content should be placed under tomcat’s “webapps” directory
  • 10. • $CATALINA_HOMEwebappshelloservlet": This directory is known as context root for the web context "helloservlet". It contains the resources that are visible by the clients, such as HTML, CSS, Scripts and images. These resources will be delivered to the clients as it is. You could create sub-directories such as images, css and scripts, to further categories the resources accessible by clients. • "$CATALINA_HOMEwebappshelloservletWEB-INF": This is a hidden directory that is used by the server. It is NOT accessible by the clients directly (for security reason). This is where you keep your application- specific configuration files such as "web.xml" (which we will elaborate later). It's sub-directories contain program classes, source files, and libraries. • "$CATALINA_HOMEwebappshelloservletWEB-INFsrc": Keep the Java program source files. It is optional but a good practice to separate the source files and classes to facilitate deployment. • "$CATALINA_HOMEwebappshelloservletWEB-INFclasses": Keep the Java classes (compiled from the source codes). Classes defined in packages must be kept according to the package directory structure. • "$CATALINA_HOMEwebappshelloservletWEB-INFlib": keep the libraries (JAR-files), which are provided by other packages, available to this webapp only.
  • 11. <HTML> <HEAD> <TITLE>Introductions</TITLE> </HEAD> <BODY> <FORM METHOD=GET ACTION="/servlet/Hello"> If you don't mind me asking, what is your name? <INPUT TYPE=TEXT NAME="name"><P> <INPUT TYPE=SUBMIT> </FORM> </BODY> </HTML>
  • 12. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Hello extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String name = req.getParameter("name"); out.println("<HTML>"); out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>"); out.println("<BODY>"); out.println("Hello, " + name); out.println("</BODY></HTML>"); } public String getServletInfo() { return "A servlet that knows the name of the person to whom it's" + "saying hello"; } }
  • 13. The web.xml file defines each servlet and JSP <?xml version="1.0" encoding="ISO-8859-1"?> page within a Web Application. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">  The file goes into the WEB-INF <web-app> directory <servlet> <servlet-name> hi </servlet-name> <servlet-class> HelloWorld </servlet-class> </servlet> <servlet-mapping> <servlet-name> hi </servlet-name> <url-pattern> /hello.html </url-pattern> </servlet-mapping> </web-app>
  • 14. Compile the packages: "C:Program FilesJavajdk1.6.0_17binjavac" <Package Name>*.java -d .  If external (outside the current working directory) classes and libraries are used, we will need to explicitly define the CLASSPATH to list all the directories which contain used classes and libraries set CLASSPATH=C:libjarsclassifier.jar ;C:UserProfilingjarsprofiles.jar  -d (directory) ◦ Set the destination directory for class files. The destination directory must already exist. ◦ If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed.  -classpath ◦ Set the user class path, overriding the user class path in the CLASSPATH environment variable. ◦ If neither CLASSPATH or -classpath is specified, the user class path consists of the current directory java -classpath C:javaMyClasses utility.myapp.Cool
  • 15. What does the following command do? Javac –classpath .;..classes;”D:Serversapache- tomcat-6.0.26-windows-x86apache-tomcat- 6.0.26libservlet-api.jar” src*.java –d ./test
  • 16.
  • 17. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SimpleCounter extends HttpServlet { int count = 0; public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); count++; out.println("Since loading, this servlet has been accessed " + count + " times."); } }
  • 18. JSP HTML <HTML> <HTML> <BODY> <BODY> Hello, world Hello! The time is now <%= new java.util.Date() %> </BODY> </BODY> </HTML> </HTML>  Same as HTML, but just save it with .jsp extension
  • 19. AUA – CoE Apr.11, Spring 2012
  • 20. 1. Hashtable is synchronized, whereas HashMap is not. 1. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones. 2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.