SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Introduction to
     Java Enterprise
         Edition

    Configuring JBoss within Eclipse
        
            Write your first Servlet

                       Fernando Gil
                   lobho.gil@gmail.com
                       Marzo 2012
Agenda


    How to configure JBoss AS within Eclipse in
    order to start the develop of JavaEE
    applications.

    We'll write our first Servlet class.

    We'll discuss the deployment descriptor.
JBoss AS 6.1 & Eclipse Indigo

        First download Eclipse IDE for Java Developers from:
        http://www.eclipse.org/downloads and JBoss 6.1 from:
        http://www.jboss.org/jbossas/downloads/

        Open Eclipse.

        Create a New Server:
    Go to File/New/Other
    



    Select Server Option
    



    Search JBoss 6.x
    



    Browse JBoss Home
    



    Directory (the folder
    where you saved
    JBoss)
    Click Finish
    
Important

        If you can not find JBoss 6.x in the servers list,
        try to Download additional server adapters:

    
     Sometimes eclipse can
    not find the JBoss
    adapters, in that case
    check this video tutorial
    to solve the problem:
    Eclipse & JBoss AS 6
Dynamic Web
         Project


    Open Eclipse and select File/New/
    Dynamic Web Project

    Set the Project Name and the
    location

    In Target Runtime we must select
    the runtime of JBoss 6.x

    The Dynamic web module version
    will be set automatically

    We can Click Finish
Creating our
          Servlet

    In order to keep the
    example simple, we'll
    create     a    servlet
    selecting
    File/New/Class and set
    the values like in the
    picture:
The Code
package com.dss.tut;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FirstServlet extends HttpServlet {
      /* The service() method handles requests and creates responses.
       * The servlet container automatically calls this method when
       * it gets any request for this servlet.*/
      public void service(HttpServletRequest req, HttpServletResponse resp)
                   throws IOException, ServletException{
             PrintWriter pw = resp.getWriter();
           pw.println("<html>");
           pw.println(" <head></head>");
           pw.println(" <body>");
           pw.println(" <h1>Hello! this is my first
Servlet</h1>");
           pw.println(" </body>");
           pw.println("</html>");
      }
}
Deployment Descriptor

    We must indicate to the Application Server the configurations of our Servlets. The Deployment
    descriptor is a XML file to accomplish this task. We will talk more about this file later. By the moment
    we need to create a new file called web.xml in the directory: WebContent/WEB-INF of our project.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns="http://java.sun.com/xml/ns/javaee"
                  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
                  id="WebApp_ID" version="3.0">

           <servlet>
                  <!-- Define our servlet indicating one name to identify it and
                         the class which represent it including the package -->
                  <servlet-name>First</servlet-name>
                  <servlet-class>com.dss.tut.FirstServlet</servlet-class>
           </servlet>
        <servlet-mapping>
           <!-- Link one existent servlet with an url. Whit this we can specify
                  the way we can access the Servlet by the browser-->
                  <servlet-name>First</servlet-name>
                  <url-pattern>/MyServlet</url-pattern>
           </servlet-mapping>
    </web-app>
Compilation and Deployment

    Now we just need to select our project, right click, Run As.., Run on Server,
    Select our JBoss Server and wait.

    Remember the url pattern that we specified in the deployment descriptor,
    because that is the way we'll access to the Servlet.
Next Lesson:
JPS Technology
         Fernando Gil
     lobho.gil@gmail.com
         Marzo 2012

Weitere ähnliche Inhalte

Was ist angesagt?

JavaScript Testing VIA Selenium
JavaScript Testing VIA SeleniumJavaScript Testing VIA Selenium
JavaScript Testing VIA Selenium
Adam Christian
 

Was ist angesagt? (20)

Deploying and running mule standalone
Deploying and running mule standaloneDeploying and running mule standalone
Deploying and running mule standalone
 
Getting started with Selenium 2
Getting started with Selenium 2Getting started with Selenium 2
Getting started with Selenium 2
 
Testing Agile Web Services from soapUI
Testing Agile Web Services from soapUITesting Agile Web Services from soapUI
Testing Agile Web Services from soapUI
 
Mule with velocity
Mule with velocityMule with velocity
Mule with velocity
 
Api webservice setupinstructions
Api webservice setupinstructionsApi webservice setupinstructions
Api webservice setupinstructions
 
JavaScript Testing VIA Selenium
JavaScript Testing VIA SeleniumJavaScript Testing VIA Selenium
JavaScript Testing VIA Selenium
 
Idempotent filter in Mule
Idempotent filter in MuleIdempotent filter in Mule
Idempotent filter in Mule
 
Spring Boot Showcase
Spring Boot ShowcaseSpring Boot Showcase
Spring Boot Showcase
 
Maven tools & archetypes
Maven tools & archetypesMaven tools & archetypes
Maven tools & archetypes
 
Mule ESB - How to convert from Xml to Json in 5 minutes
Mule ESB - How to convert from Xml to Json in 5 minutesMule ESB - How to convert from Xml to Json in 5 minutes
Mule ESB - How to convert from Xml to Json in 5 minutes
 
Example mule
Example muleExample mule
Example mule
 
Deploying and running in mule standalone
Deploying and running in mule standaloneDeploying and running in mule standalone
Deploying and running in mule standalone
 
Integration with Dropbox using Mule ESB
Integration with Dropbox using Mule ESBIntegration with Dropbox using Mule ESB
Integration with Dropbox using Mule ESB
 
Mule with drools
Mule with droolsMule with drools
Mule with drools
 
Sails.js Intro
Sails.js IntroSails.js Intro
Sails.js Intro
 
The WordPress developer's toolkit
The WordPress developer's toolkit The WordPress developer's toolkit
The WordPress developer's toolkit
 
Mule management console installation with Tomcat
Mule management console installation with TomcatMule management console installation with Tomcat
Mule management console installation with Tomcat
 
Mule esb - How to connect to a MySql Database in 5 minutes
Mule esb - How to connect to a MySql Database in 5 minutesMule esb - How to connect to a MySql Database in 5 minutes
Mule esb - How to connect to a MySql Database in 5 minutes
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Mule velocity
Mule velocityMule velocity
Mule velocity
 

Ähnlich wie Java EE 02-First Servlet

Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
rvpprash
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Raghu nath
 
Jsp and servlet_netbeans-webapps
Jsp and servlet_netbeans-webappsJsp and servlet_netbeans-webapps
Jsp and servlet_netbeans-webapps
OPENLANE
 

Ähnlich wie Java EE 02-First Servlet (20)

Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
Servlet Demo (2).pptx
Servlet Demo (2).pptxServlet Demo (2).pptx
Servlet Demo (2).pptx
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
 
Jboss App Server
Jboss App ServerJboss App Server
Jboss App Server
 
Servlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpServlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtp
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
 
Jsf tutorial
Jsf tutorialJsf tutorial
Jsf tutorial
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Cis 274 intro
Cis 274   introCis 274   intro
Cis 274 intro
 
1 app 2 developers 3 servers
1 app 2 developers 3 servers1 app 2 developers 3 servers
1 app 2 developers 3 servers
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Geoserver GIS Mapping Solution
Geoserver GIS Mapping SolutionGeoserver GIS Mapping Solution
Geoserver GIS Mapping Solution
 
Jdbc
JdbcJdbc
Jdbc
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
Weblogic 12c Graphical Mode installation steps in Windows
Weblogic 12c Graphical Mode installation steps in Windows Weblogic 12c Graphical Mode installation steps in Windows
Weblogic 12c Graphical Mode installation steps in Windows
 
12c weblogic installation steps for Windows
12c weblogic installation steps for Windows12c weblogic installation steps for Windows
12c weblogic installation steps for Windows
 
Jboss Tutorial Basics
Jboss Tutorial BasicsJboss Tutorial Basics
Jboss Tutorial Basics
 
Jsp and servlet_netbeans-webapps
Jsp and servlet_netbeans-webappsJsp and servlet_netbeans-webapps
Jsp and servlet_netbeans-webapps
 

Kürzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Kürzlich hochgeladen (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Java EE 02-First Servlet

  • 1. Introduction to Java Enterprise Edition  Configuring JBoss within Eclipse  Write your first Servlet Fernando Gil lobho.gil@gmail.com Marzo 2012
  • 2. Agenda  How to configure JBoss AS within Eclipse in order to start the develop of JavaEE applications.  We'll write our first Servlet class.  We'll discuss the deployment descriptor.
  • 3. JBoss AS 6.1 & Eclipse Indigo  First download Eclipse IDE for Java Developers from: http://www.eclipse.org/downloads and JBoss 6.1 from: http://www.jboss.org/jbossas/downloads/  Open Eclipse.  Create a New Server: Go to File/New/Other  Select Server Option  Search JBoss 6.x  Browse JBoss Home  Directory (the folder where you saved JBoss) Click Finish 
  • 4. Important  If you can not find JBoss 6.x in the servers list, try to Download additional server adapters:  Sometimes eclipse can not find the JBoss adapters, in that case check this video tutorial to solve the problem: Eclipse & JBoss AS 6
  • 5. Dynamic Web Project  Open Eclipse and select File/New/ Dynamic Web Project  Set the Project Name and the location  In Target Runtime we must select the runtime of JBoss 6.x  The Dynamic web module version will be set automatically  We can Click Finish
  • 6. Creating our Servlet  In order to keep the example simple, we'll create a servlet selecting File/New/Class and set the values like in the picture:
  • 7. The Code package com.dss.tut; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class FirstServlet extends HttpServlet { /* The service() method handles requests and creates responses. * The servlet container automatically calls this method when * it gets any request for this servlet.*/ public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ PrintWriter pw = resp.getWriter(); pw.println("<html>"); pw.println(" <head></head>"); pw.println(" <body>"); pw.println(" <h1>Hello! this is my first Servlet</h1>"); pw.println(" </body>"); pw.println("</html>"); } }
  • 8. Deployment Descriptor  We must indicate to the Application Server the configurations of our Servlets. The Deployment descriptor is a XML file to accomplish this task. We will talk more about this file later. By the moment we need to create a new file called web.xml in the directory: WebContent/WEB-INF of our project. <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <servlet> <!-- Define our servlet indicating one name to identify it and the class which represent it including the package --> <servlet-name>First</servlet-name> <servlet-class>com.dss.tut.FirstServlet</servlet-class> </servlet> <servlet-mapping> <!-- Link one existent servlet with an url. Whit this we can specify the way we can access the Servlet by the browser--> <servlet-name>First</servlet-name> <url-pattern>/MyServlet</url-pattern> </servlet-mapping> </web-app>
  • 9. Compilation and Deployment  Now we just need to select our project, right click, Run As.., Run on Server, Select our JBoss Server and wait.  Remember the url pattern that we specified in the deployment descriptor, because that is the way we'll access to the Servlet.
  • 10. Next Lesson: JPS Technology Fernando Gil lobho.gil@gmail.com Marzo 2012