SlideShare a Scribd company logo
Java™ Servlet 3.0 API: What's new and exciting


Rajiv Mordani
Senior Staff Engineer, Sun Microsystems
TS-5415
Learn about the new features in the
Java™ Servlet 3.0 API




                                  2008 JavaOneSM Conference | java.sun.com/javaone |   2
Agenda

 Overview
 Pluggability
 Ease of Development
 Async servlet support
 Security
 Others
 Status
 Summary




                         2008 JavaOneSM Conference | java.sun.com/javaone |   3
Overview
 Java™ Servlet 3.0 API – JSR 315
 Has about 20 members in the expert group with a good mix of
 representation from the major Java™ EE vendors, web container
 vendors and individual web framework authors
 Main areas of improvements and additions are -
  • Pluggability
  • Ease of development
  • Async servlet support
  • Security enhancements
 Note: Specification in early draft and things can change
  • The good news is that the community still has time to provide feedback



                                                 2008 JavaOneSM Conference | java.sun.com/javaone |   4
Agenda

 Overview
 Pluggability
 Ease of Development
 Async servlet support
 Security
 Others
 Status
 Summary




                         2008 JavaOneSM Conference | java.sun.com/javaone |   5
Pluggability
 Make it possible to use framework and libraries with no
 additional configuration
 Modularizing web.xml to allow frameworks / libraries to
 have their own entities defined and self-contained within
 the framework
 Adding APIs to ServletContext to allow addition of
 Servlets, Filters and Listeners to a web application
 at application startup time.
 Use of annotations to declare all the components within a
 web application




                                       2008 JavaOneSM Conference | java.sun.com/javaone |   6
Pluggability - Modularization of web.xml
 Current users of framework need to edit their application's
 web.xml to
  • Define a Java™ Servlet provided by the framework (typically a
    controller Java™ Servlet )
  • Define Filters that the framework needs in order to be used within
    a web application (logging for example or Filters to implement
    security constraints)
  • Define listeners so that appropriate action can be taken at different
    points in the application / component's life cycle.
 Monolithic web.xml can become complex to maintain as the
 dependencies of the application increases
 Each framework needs to document for the developer what
 all must be declared in the web.xml


                                                   2008 JavaOneSM Conference | java.sun.com/javaone |   7
Pluggability – Modularization of web.xml
 Java™ Servlet 3.0 specification introduces the concept of
 modular web.xml
 Each framework can define it's own web.xml and include it in
 the jar file's META-INF directory
 The developer needs to include the framework jar in the
 application
 At deployment the container is responsible for discovering
 the web.xml fragments and processing them.
 Introduce new element – web-fragment that can define
 servlets, filters and listeners as child elements.




                                         2008 JavaOneSM Conference | java.sun.com/javaone |   8
Pluggability - example new elements in
web.xml
<web-fragment>
  <servlet>
    <servlet-name>welcome</servlet-name>
    <servlet-class>
      WelcomeServlet
    </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>welcome</servlet-name>
    <url-pattern>/Welcome</url-pattern>
  </servlet-mapping>
...
</web-fragment>
                                 2008 JavaOneSM Conference | java.sun.com/javaone |   9
Pluggability – Configuration methods in
ServletContext
 In addition to web.xml modularization methods added to the
 ServletContext to declare and configure servlets and filters.
 Can only be called at context initialization time.
 Allows to
  • Declare a new Servlet
  • Define a url mapping for the Servlet declared
  • Declare a Filter
  • Define a url mapping for the Filter
 Enables applications to load Servlets and filters at runtime
 that are needed




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   10
Pluggability – APIs in ServletContext example
@ServletContextListener
public class MyListener {
    public void contextInitialized
                (ServletContextEvent sce) {
        ServletContext sc = sce.getServletContext();
        sc.addServlet("myServlet",
                       "Sample servlet",
                       "foo.bar.MyServlet",
                        null, -1);
        sc.addServletMapping("myServlet",
                             new String[]
                             {"/urlpattern/*"});
    }
}

                                    2008 JavaOneSM Conference | java.sun.com/javaone |   11
Pluggability – APIs in ServletContext example
@ServletContextListener
public class MyListener {
    public void contextInitialized
                (ServletContextEvent sce) {
        ServletContext sc = sce.getServletContext();
        sc.addFilter("myFilter",
                       "Sample Filter",
                       "foo.bar.MyFilter",
                        null);
        sc.addFilterMapping("myFilter",
                             new String[]
                             {"/urlpattern/*"},
                            “myServlet”,
                            DispatcherType.REQUEST,
                            false);
    }
}
                                        2008 JavaOneSM Conference | java.sun.com/javaone |   12
Agenda

 Overview
 Pluggability
 Ease of Development
 Async servlet support
 Security
 Others
 Status
 Summary




                         2008 JavaOneSM Conference | java.sun.com/javaone |   13
Ease of Development
 Focus on ease of development in Java™ Servlet 3.0 API
 Enhance Java™ Servlet APIs to use newer language features
 Annotations for declarative style of programming
 Generics for better compile time error checking and type safety
 web.xml optional (was already optional for Java™ EE 5)
  • Restricted to JSPs and static resources only
 Better defaults / convention over configuration




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   14
Ease of Development – defining a servlet
 Define a servlet using a @Servlet annotation
 Must contain a url-mapping
 All other fields optional with reasonable defaults –
  • example the “name” of the servlet is the fully qualified class name if
    none is specified.
  • Can define the appropriate http methods using the annotations @GET,
    @PUT, @POST, @DELETE, @HEAD
  • @HttpMethod meta-annotation allows extensions
 Can use the web.xml to override annotation values




                                                   2008 JavaOneSM Conference | java.sun.com/javaone |   15
Servlet example – 2.5 style
                                web.xml
public class SimpleSample       <web-app>
extends HttpServlet {             <servlet>
                                       <servlet-name>
    public void doGet                      MyServlet
    (HttpServletRequest req,          </servlet-name>
     HttpServletResponse res)         <servlet-class>
    {                                  samples.SimpleSample
                                      </servlet-class>
                                  </servlet>
    }
                                  <servlet-mapping>
}                                     <servlet-name>
                                        MyServlet
                                      </servlet-name>
                                      <url-pattern>
                                        /MyApp
                                      </url-pattern>
                                  </servlet-mapping>
                                ...
                                </web-app>

                                                    2008 JavaOneSM Conference | java.sun.com/javaone |   16
Ease of development – Defining a servlet


 @Servlet(urlMapping={“/foo”})
 public class SimpleSample {

 }




                                 2008 JavaOneSM Conference | java.sun.com/javaone |   17
Code Sample

 @Servlet(urlMapping={“/foo”, “/bar”},
          name=”MyServlet”)
 public class SampleUsingAnnotationAttributes {
     @GET
     public void handleGet(HttpServletRequest req,   
                            HttpServletResponse res)
     {

     }

 }




                                   2008 JavaOneSM Conference | java.sun.com/javaone |   18
Ease of development – Defining a Filter
 Define a Filter using a @ServletFilter annotation
 Must contain a @FilterMapping annotation
 All other fields optional with reasonable defaults




                                       2008 JavaOneSM Conference | java.sun.com/javaone |   19
Code Sample

 package samples;
 import javax.servlet.http.annotation.*;

 @ServletFilter
 @FilterMapping(urlPattern=”/foo”)
 public class SampleFilter {

     public void doFilter(HttpServletRequest req,   
                          HttpServletResponse res)
     {

     }

 }

                                     2008 JavaOneSM Conference | java.sun.com/javaone |   20
Ease of development – Defining a
ServletContextListener
 Define a context listener using a
 @ServletContextListener annotation




                                2008 JavaOneSM Conference | java.sun.com/javaone |   21
Ease of Developmnt – ServletContext
example
@ServletContextListener
public class MyListener {
    public void contextInitialized
                (ServletContextEvent sce) {
        ServletContext sc = sce.getServletContext();
        sc.addServlet("myServlet",
                       "Sample servlet",
                       "foo.bar.MyServlet",
                        null, -1);
        sc.addServletMapping("myServlet",
                             new String[]
                             {"/urlpattern/*"});
    }
}

                                    2008 JavaOneSM Conference | java.sun.com/javaone |   22
Agenda

 Overview
 Pluggability
 Ease of Development
 Async servlet support
 Security
 Others
 Status
 Summary




                         2008 JavaOneSM Conference | java.sun.com/javaone |   23
Async servlet – Use cases
 Comet style of application
 Async Web proxy
 Async Web services




                              2008 JavaOneSM Conference | java.sun.com/javaone |   24
Async servlet support – popular use case
Comet
 Primer
  • Rely on a persistent HTTP connection between server and client
  • Two strategies
     • Streaming - browser opens a single persistent connection to the server for
       all Comet events each time the server sends a new event, the browser
       interprets it.
     • Long polling - a new request for each event (or set of events)
  • Standardization efforts as part of the Bayeux protocol
 Implementation specific APIs available today in the various
 Java™ Servlet containers.
 APIs added to Java™ Servlet 3.0 specification to enable Comet
 style programming
 Request can be suspended and resumed


                                                       2008 JavaOneSM Conference | java.sun.com/javaone |   25
Async servlet support - Suspending a request
 Request can be suspended by the application
 Allows the container to not block on a request that needs
 access to a resource – for example access to a DataSource or
 wait for a response from a call to a WebService.
 When resumed the Request is re-dispatched through the
 filters for processing.
  • Results in an additional thread for handling the new request
 The resume method on the request resumes processing
  • Can be used to push timely events in multi-user applications
 The complete method to indicate the completion of request
 processing
 Can query if a request is suspended, resumed or has
 timed out.

                                            2008 JavaOneSM Conference | java.sun.com/javaone |   26
Async servlet support – methods added to
ServletRequest
 Methods added to ServletRequest for suspending, resuming
 and querying for status -
  • void suspend(long timeOutMs);
  • void resume();
  • void complete();
  • boolean isSuspended();
  • boolean isResumed();
  • boolean isTimeout();




                                       2008 JavaOneSM Conference | java.sun.com/javaone |   27
Async servlet support – Events on
RequestListener
 Corresponding events fired for changes to request processing.
 Notification for suspend, resume and complete available for
 developers via the ServletRequestListener
 Methods added to ServletRequestListener
  • void requestSuspended(ServletRequestEvent rre);
  • void requestResumed(ServletRequestEvent rre);
  • void requestCompleted(ServletRequestEvent rre);




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   28
Async servlet support – methods added to
Response
 Methods added to ServletResponse for disabling, enabling
 and querying for status -
  • void disable();
  • void isDisabled();
  • void enable();




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   29
Async servlet to web services call




                               2008 JavaOneSM Conference | java.sun.com/javaone |   30
Agenda

 Overview
 Pluggability
 Ease of Development
 Async servlet support
 Security
 Others
 Status
 Summary




                         2008 JavaOneSM Conference | java.sun.com/javaone |   31
Security
 Ability to login and logout programmatically
 Methods added to ServletRequest to force a login and
 ability to logout
 Still being discussed in the EG.
 Proposal to add login and logout method to
  • HttpServletRequest
  • HttpServletRequestWrapper
  • HttpSession (logout only)




                                     2008 JavaOneSM Conference | java.sun.com/javaone |   32
Security – login and logout
 Login method intended to allow an application or framework
 to force a container mediated authentication from within an
 unconstrained request context
 Login requires access to the HttpResponse object to set
 the www-authenticate header.
  • Available through new methods added to the request to give access to
    the corresponding response object
 logout methods are provided to allow an application to reset
 the authentication state of a request without requiring that
 authentication be bound to an HttpSession
 Still in discussion in the Expert Group and not closed upon.



                                                 2008 JavaOneSM Conference | java.sun.com/javaone |   33
Agenda

 Overview
 Pluggability
 Ease of Development
 Async servlet support
 Security
 Others
 Status
 Summary




                         2008 JavaOneSM Conference | java.sun.com/javaone |   34
Others – HttpOnly Cookie support
 Added support for HttpOnlyCookies
 Prevents access to the cookie from client side scripting code
 Prevents cross-site scripting attacks.
 Method added to Cookie to set and query if it is an
 HttpOnly cookie




                                           2008 JavaOneSM Conference | java.sun.com/javaone |   35
Others – Session tracking cookie
configuration
 Ability to set the session tracking cookie configuration for the
 corresponding ServletContext
 Supports multiple Session tracking mode – COOKIE, URL, SSL




                                            2008 JavaOneSM Conference | java.sun.com/javaone |   36
Pending discussion in the expert group
 Miscellaneous items to be done for Java™ Servlet 3.0 API
 • File upload
 • Container wide init-params
 • Clarifications from previous releases
 • Enablement of JAX-RS / JSF 2.0 (if any changes needed)




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   37
Java EE profiles
 Java EE 6 specification introducing notion of profiles
 Targeting a web profile for Java EE 6
 Web profile to be based on Servlets and JSPs
 Still being discussed in the Java EE 6 expert group
 Roberto solicited feedback from the community
 Varying opinions of what should be in the profile
 Still need to close on in the Java EE 6 expert group




                                            2008 JavaOneSM Conference | java.sun.com/javaone |   38
Web/EJB Technology Application in
JavaTM EE Platform 5
           foo.ear                           foo.ear

                                    lib/foo_common.jar
  foo_web.war
  WEB-INF/web.xml                   com/acme/Foo.class
  WEB-INF/classes/
   com/acme/FooServlet.class        foo_web.war
  WEB-INF/classes
   com/acme/Foo.class          OR   WEB-INF/web.xml
                                    WEB-INF/classes/
                                     com/acme/FooServlet.class
  foo_ejb.jar
  com/acme/FooBean.class            foo_ejb.jar
  com/acme/Foo.class
                                    com/acme/FooBean.class


                                           2008 JavaOneSM Conference | java.sun.com/javaone |   39
Web/EJB Technology Application in
JavaTM EE Platform 6

                    foo.war

            WEB-INF/classes/
             com/acme/FooServlet.class

            WEB-INF/classes/
             com/acme/FooBean.class




                                         2008 JavaOneSM Conference | java.sun.com/javaone |   40
EJB in a WAR file
 Goal is to remove an artificial packaging restriction
  • NOT to create a new flavor of EJB component
 EJB component behavior is independent of packaging
 Full EJB container functionality available




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   41
Agenda

 Overview
 Pluggability
 Ease of Development
 Comet
 Security
 Status
 Summary




                       2008 JavaOneSM Conference | java.sun.com/javaone |   42
Status

 Currently in Early Draft Review
 Public Review in summer of this year
 Proposed final draft and final release aligned with Java™ EE 6
 Early access to bits of implementation to be available via
 Project GlassFish




                                           2008 JavaOneSM Conference | java.sun.com/javaone |   43
Agenda

 Overview
 Pluggability
 Ease of Development
 Comet
 Security
 Status
 Summary




                       2008 JavaOneSM Conference | java.sun.com/javaone |   44
Summary

Lot of exciting things happening in the Java™ Servlet 3.0 API
   • Pluggability for frameworks
   • Ease of Development for developers
   • Comet support to enable modern web 2.0 style applications
   • Security enhancements to enable programmatic login / logout
   • Miscellaneous improvements for better developer experience
  Make the life of framework developers and users much easier
  Implementation being done in open source as part of
  GlassFish project




                                            2008 JavaOneSM Conference | java.sun.com/javaone |   45
GlassFish Community
    Open Source, Enterprise Ready & Extendable

•GlassFish V3 Tech Preview 2 Available now!        • GlassFish Partner Initiative
    •Modular OSGi architecture – easy to deploy,
    Develop and Extend
                                                       •Expanding the ecosystem for
•GlassFish V2 – Production Ready                       partners.
 ● Fastest open source app server with
                                                   • Enterprise and Mission Critical
   Clustering, High Availability, Load Balancing     Support
                                                       sun.com/software/products/appsrvr
 ● Support for jMaki, Comet, Ajax, Ruby and
                                                   • GlassFish Unlimited Pricing
   Groovy
•GlassFish ESB
                                                        •Fixed price, unlimited
 ● Core SOA functions now embedded in
                                                        deployments
   GlassFish                                            •Combine w/ MySQL Unlimited
•GlassFish Communications App Server               • Tools Integration
 ● SIP servlet technology for converged
                                                       •NetBeans and Eclipse
   services
                                                                  glassfish.org
 Always free to download, deploy and distribute

                                                        2008 JavaOneSM Conference | java.com.sun/javaone |   46
For More Information

 Official JSR Page
  • http://jcp.org/en/jsr/detail?id=315
 JAX-RS – TS 5425
 JSF 2.0 – TS 5979
 Mailing list for webtier related issues -
 webtier@glassfish.dev.java.net
 Rajiv's blog
  • http://weblogs.java.net/blog/mode




                                             2008 JavaOneSM Conference | java.sun.com/javaone |   47
Rajiv Mordani
Senior Staff Engineer, Sun Microsystems
TS-5415




                                      2008 JavaOneSM Conference | java.sun.com/javaone |   48

More Related Content

PDF
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
PDF
JavaOne India 2011 - Servlets 3.0
PDF
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
ODP
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
PDF
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
PDF
GIDS 2012: PaaSing a Java EE Application
PDF
GIDS 2012: Java Message Service 2.0
ODP
Spring Portlet MVC
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
JavaOne India 2011 - Servlets 3.0
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: Java Message Service 2.0
Spring Portlet MVC

What's hot (20)

PDF
Java EE 6 and GlassFish v3: Paving the path for future
PDF
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
PDF
Java EE7 Demystified
PPT
Java EE7 in action
PDF
Jsp servlets
PPTX
Java Server Faces + Spring MVC Framework
PDF
Servlets lecture1
PDF
JavaEE6 my way
PDF
Advanced liferay architecture clustering and high availability
PPT
Spring MVC
PDF
quickguide-einnovator-7-spring-mvc
PDF
Introduction to Spring Framework
DOC
PPT
Java Server Faces (JSF) - Basics
DOC
Java Servlets & JSP
PDF
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
KEY
Multi client Development with Spring
PDF
Deep Dive Hands-on in Java EE 6 - Oredev 2010
PDF
Java EE 6 & GlassFish v3 @ DevNexus
KEY
Multi Client Development with Spring
Java EE 6 and GlassFish v3: Paving the path for future
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
Java EE7 Demystified
Java EE7 in action
Jsp servlets
Java Server Faces + Spring MVC Framework
Servlets lecture1
JavaEE6 my way
Advanced liferay architecture clustering and high availability
Spring MVC
quickguide-einnovator-7-spring-mvc
Introduction to Spring Framework
Java Server Faces (JSF) - Basics
Java Servlets & JSP
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Multi client Development with Spring
Deep Dive Hands-on in Java EE 6 - Oredev 2010
Java EE 6 & GlassFish v3 @ DevNexus
Multi Client Development with Spring
Ad

Similar to Introduction to java servlet 3.0 api javaone 2008 (20)

PDF
Introduction to java servlet 3.0 api javaone 2009
PDF
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
PDF
Servlet30 20081218
PDF
Coursejspservlets00
PDF
Jeetrainers.com coursejspservlets00
PDF
Boston 2011 OTN Developer Days - Java EE 6
PDF
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
PDF
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
PDF
Java EE 6 = Less Code + More Power
PDF
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
ODP
servlet 2.5 & JSP 2.0
DOCX
Html servlet example
DOC
Servlet basics
PDF
JAX-RS Creating RESTFul services
PPTX
SCWCD : The servlet container : CHAP : 4
PPTX
SCWCD : Servlet web applications : CHAP : 3
PPTX
SCWCD : Servlet web applications : CHAP 3
PPT
Introduction to the Servlet / JSP course
PPT
Ppt for Online music store
PDF
Java EE 01-Servlets and Containers
Introduction to java servlet 3.0 api javaone 2009
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlet30 20081218
Coursejspservlets00
Jeetrainers.com coursejspservlets00
Boston 2011 OTN Developer Days - Java EE 6
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 = Less Code + More Power
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
servlet 2.5 & JSP 2.0
Html servlet example
Servlet basics
JAX-RS Creating RESTFul services
SCWCD : The servlet container : CHAP : 4
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP 3
Introduction to the Servlet / JSP course
Ppt for Online music store
Java EE 01-Servlets and Containers
Ad

More from JavaEE Trainers (8)

PDF
Introduction tomcat7 servlet3
PPT
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
PPT
Servlet/JSP course chapter 1: Introduction to servlets
PDF
Jsp quick reference card
PDF
jsp, javaserver pages, Card20
PPT
Struts2 course chapter 2: installation and configuration
PPT
Struts2 course chapter 1: Evolution of Web Applications
PPT
Struts2 Course: Introduction
Introduction tomcat7 servlet3
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 1: Introduction to servlets
Jsp quick reference card
jsp, javaserver pages, Card20
Struts2 course chapter 2: installation and configuration
Struts2 course chapter 1: Evolution of Web Applications
Struts2 Course: Introduction

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
NewMind AI Weekly Chronicles - August'25 Week I
NewMind AI Monthly Chronicles - July 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Introduction to java servlet 3.0 api javaone 2008

  • 1. Java™ Servlet 3.0 API: What's new and exciting Rajiv Mordani Senior Staff Engineer, Sun Microsystems TS-5415
  • 2. Learn about the new features in the Java™ Servlet 3.0 API 2008 JavaOneSM Conference | java.sun.com/javaone | 2
  • 3. Agenda Overview Pluggability Ease of Development Async servlet support Security Others Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 3
  • 4. Overview Java™ Servlet 3.0 API – JSR 315 Has about 20 members in the expert group with a good mix of representation from the major Java™ EE vendors, web container vendors and individual web framework authors Main areas of improvements and additions are - • Pluggability • Ease of development • Async servlet support • Security enhancements Note: Specification in early draft and things can change • The good news is that the community still has time to provide feedback 2008 JavaOneSM Conference | java.sun.com/javaone | 4
  • 5. Agenda Overview Pluggability Ease of Development Async servlet support Security Others Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 5
  • 6. Pluggability Make it possible to use framework and libraries with no additional configuration Modularizing web.xml to allow frameworks / libraries to have their own entities defined and self-contained within the framework Adding APIs to ServletContext to allow addition of Servlets, Filters and Listeners to a web application at application startup time. Use of annotations to declare all the components within a web application 2008 JavaOneSM Conference | java.sun.com/javaone | 6
  • 7. Pluggability - Modularization of web.xml Current users of framework need to edit their application's web.xml to • Define a Java™ Servlet provided by the framework (typically a controller Java™ Servlet ) • Define Filters that the framework needs in order to be used within a web application (logging for example or Filters to implement security constraints) • Define listeners so that appropriate action can be taken at different points in the application / component's life cycle. Monolithic web.xml can become complex to maintain as the dependencies of the application increases Each framework needs to document for the developer what all must be declared in the web.xml 2008 JavaOneSM Conference | java.sun.com/javaone | 7
  • 8. Pluggability – Modularization of web.xml Java™ Servlet 3.0 specification introduces the concept of modular web.xml Each framework can define it's own web.xml and include it in the jar file's META-INF directory The developer needs to include the framework jar in the application At deployment the container is responsible for discovering the web.xml fragments and processing them. Introduce new element – web-fragment that can define servlets, filters and listeners as child elements. 2008 JavaOneSM Conference | java.sun.com/javaone | 8
  • 9. Pluggability - example new elements in web.xml <web-fragment> <servlet> <servlet-name>welcome</servlet-name> <servlet-class> WelcomeServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>welcome</servlet-name> <url-pattern>/Welcome</url-pattern> </servlet-mapping> ... </web-fragment> 2008 JavaOneSM Conference | java.sun.com/javaone | 9
  • 10. Pluggability – Configuration methods in ServletContext In addition to web.xml modularization methods added to the ServletContext to declare and configure servlets and filters. Can only be called at context initialization time. Allows to • Declare a new Servlet • Define a url mapping for the Servlet declared • Declare a Filter • Define a url mapping for the Filter Enables applications to load Servlets and filters at runtime that are needed 2008 JavaOneSM Conference | java.sun.com/javaone | 10
  • 11. Pluggability – APIs in ServletContext example @ServletContextListener public class MyListener { public void contextInitialized               (ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); sc.addServlet("myServlet",                        "Sample servlet",                      "foo.bar.MyServlet",                         null, -1); sc.addServletMapping("myServlet", new String[]                            {"/urlpattern/*"}); } } 2008 JavaOneSM Conference | java.sun.com/javaone | 11
  • 12. Pluggability – APIs in ServletContext example @ServletContextListener public class MyListener { public void contextInitialized               (ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); sc.addFilter("myFilter",                        "Sample Filter",                      "foo.bar.MyFilter",                         null); sc.addFilterMapping("myFilter", new String[]                            {"/urlpattern/*"},                           “myServlet”,                           DispatcherType.REQUEST,                           false); } } 2008 JavaOneSM Conference | java.sun.com/javaone | 12
  • 13. Agenda Overview Pluggability Ease of Development Async servlet support Security Others Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 13
  • 14. Ease of Development Focus on ease of development in Java™ Servlet 3.0 API Enhance Java™ Servlet APIs to use newer language features Annotations for declarative style of programming Generics for better compile time error checking and type safety web.xml optional (was already optional for Java™ EE 5) • Restricted to JSPs and static resources only Better defaults / convention over configuration 2008 JavaOneSM Conference | java.sun.com/javaone | 14
  • 15. Ease of Development – defining a servlet Define a servlet using a @Servlet annotation Must contain a url-mapping All other fields optional with reasonable defaults – • example the “name” of the servlet is the fully qualified class name if none is specified. • Can define the appropriate http methods using the annotations @GET, @PUT, @POST, @DELETE, @HEAD • @HttpMethod meta-annotation allows extensions Can use the web.xml to override annotation values 2008 JavaOneSM Conference | java.sun.com/javaone | 15
  • 16. Servlet example – 2.5 style web.xml public class SimpleSample <web-app> extends HttpServlet { <servlet> <servlet-name> public void doGet      MyServlet     (HttpServletRequest req, </servlet-name>      HttpServletResponse res) <servlet-class>     { samples.SimpleSample </servlet-class> </servlet> } <servlet-mapping> } <servlet-name> MyServlet </servlet-name> <url-pattern> /MyApp </url-pattern> </servlet-mapping> ... </web-app> 2008 JavaOneSM Conference | java.sun.com/javaone | 16
  • 17. Ease of development – Defining a servlet @Servlet(urlMapping={“/foo”}) public class SimpleSample { } 2008 JavaOneSM Conference | java.sun.com/javaone | 17
  • 18. Code Sample @Servlet(urlMapping={“/foo”, “/bar”}, name=”MyServlet”) public class SampleUsingAnnotationAttributes { @GET public void handleGet(HttpServletRequest req,    HttpServletResponse res) { } } 2008 JavaOneSM Conference | java.sun.com/javaone | 18
  • 19. Ease of development – Defining a Filter Define a Filter using a @ServletFilter annotation Must contain a @FilterMapping annotation All other fields optional with reasonable defaults 2008 JavaOneSM Conference | java.sun.com/javaone | 19
  • 20. Code Sample package samples; import javax.servlet.http.annotation.*; @ServletFilter @FilterMapping(urlPattern=”/foo”) public class SampleFilter { public void doFilter(HttpServletRequest req,    HttpServletResponse res) { } } 2008 JavaOneSM Conference | java.sun.com/javaone | 20
  • 21. Ease of development – Defining a ServletContextListener Define a context listener using a @ServletContextListener annotation 2008 JavaOneSM Conference | java.sun.com/javaone | 21
  • 22. Ease of Developmnt – ServletContext example @ServletContextListener public class MyListener { public void contextInitialized               (ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); sc.addServlet("myServlet",                        "Sample servlet",                      "foo.bar.MyServlet",                         null, -1); sc.addServletMapping("myServlet", new String[]                            {"/urlpattern/*"}); } } 2008 JavaOneSM Conference | java.sun.com/javaone | 22
  • 23. Agenda Overview Pluggability Ease of Development Async servlet support Security Others Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 23
  • 24. Async servlet – Use cases Comet style of application Async Web proxy Async Web services 2008 JavaOneSM Conference | java.sun.com/javaone | 24
  • 25. Async servlet support – popular use case Comet Primer • Rely on a persistent HTTP connection between server and client • Two strategies • Streaming - browser opens a single persistent connection to the server for all Comet events each time the server sends a new event, the browser interprets it. • Long polling - a new request for each event (or set of events) • Standardization efforts as part of the Bayeux protocol Implementation specific APIs available today in the various Java™ Servlet containers. APIs added to Java™ Servlet 3.0 specification to enable Comet style programming Request can be suspended and resumed 2008 JavaOneSM Conference | java.sun.com/javaone | 25
  • 26. Async servlet support - Suspending a request Request can be suspended by the application Allows the container to not block on a request that needs access to a resource – for example access to a DataSource or wait for a response from a call to a WebService. When resumed the Request is re-dispatched through the filters for processing. • Results in an additional thread for handling the new request The resume method on the request resumes processing • Can be used to push timely events in multi-user applications The complete method to indicate the completion of request processing Can query if a request is suspended, resumed or has timed out. 2008 JavaOneSM Conference | java.sun.com/javaone | 26
  • 27. Async servlet support – methods added to ServletRequest Methods added to ServletRequest for suspending, resuming and querying for status - • void suspend(long timeOutMs); • void resume(); • void complete(); • boolean isSuspended(); • boolean isResumed(); • boolean isTimeout(); 2008 JavaOneSM Conference | java.sun.com/javaone | 27
  • 28. Async servlet support – Events on RequestListener Corresponding events fired for changes to request processing. Notification for suspend, resume and complete available for developers via the ServletRequestListener Methods added to ServletRequestListener • void requestSuspended(ServletRequestEvent rre); • void requestResumed(ServletRequestEvent rre); • void requestCompleted(ServletRequestEvent rre); 2008 JavaOneSM Conference | java.sun.com/javaone | 28
  • 29. Async servlet support – methods added to Response Methods added to ServletResponse for disabling, enabling and querying for status - • void disable(); • void isDisabled(); • void enable(); 2008 JavaOneSM Conference | java.sun.com/javaone | 29
  • 30. Async servlet to web services call 2008 JavaOneSM Conference | java.sun.com/javaone | 30
  • 31. Agenda Overview Pluggability Ease of Development Async servlet support Security Others Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 31
  • 32. Security Ability to login and logout programmatically Methods added to ServletRequest to force a login and ability to logout Still being discussed in the EG. Proposal to add login and logout method to • HttpServletRequest • HttpServletRequestWrapper • HttpSession (logout only) 2008 JavaOneSM Conference | java.sun.com/javaone | 32
  • 33. Security – login and logout Login method intended to allow an application or framework to force a container mediated authentication from within an unconstrained request context Login requires access to the HttpResponse object to set the www-authenticate header. • Available through new methods added to the request to give access to the corresponding response object logout methods are provided to allow an application to reset the authentication state of a request without requiring that authentication be bound to an HttpSession Still in discussion in the Expert Group and not closed upon. 2008 JavaOneSM Conference | java.sun.com/javaone | 33
  • 34. Agenda Overview Pluggability Ease of Development Async servlet support Security Others Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 34
  • 35. Others – HttpOnly Cookie support Added support for HttpOnlyCookies Prevents access to the cookie from client side scripting code Prevents cross-site scripting attacks. Method added to Cookie to set and query if it is an HttpOnly cookie 2008 JavaOneSM Conference | java.sun.com/javaone | 35
  • 36. Others – Session tracking cookie configuration Ability to set the session tracking cookie configuration for the corresponding ServletContext Supports multiple Session tracking mode – COOKIE, URL, SSL 2008 JavaOneSM Conference | java.sun.com/javaone | 36
  • 37. Pending discussion in the expert group Miscellaneous items to be done for Java™ Servlet 3.0 API • File upload • Container wide init-params • Clarifications from previous releases • Enablement of JAX-RS / JSF 2.0 (if any changes needed) 2008 JavaOneSM Conference | java.sun.com/javaone | 37
  • 38. Java EE profiles Java EE 6 specification introducing notion of profiles Targeting a web profile for Java EE 6 Web profile to be based on Servlets and JSPs Still being discussed in the Java EE 6 expert group Roberto solicited feedback from the community Varying opinions of what should be in the profile Still need to close on in the Java EE 6 expert group 2008 JavaOneSM Conference | java.sun.com/javaone | 38
  • 39. Web/EJB Technology Application in JavaTM EE Platform 5 foo.ear foo.ear lib/foo_common.jar foo_web.war WEB-INF/web.xml com/acme/Foo.class WEB-INF/classes/ com/acme/FooServlet.class foo_web.war WEB-INF/classes com/acme/Foo.class OR WEB-INF/web.xml WEB-INF/classes/ com/acme/FooServlet.class foo_ejb.jar com/acme/FooBean.class foo_ejb.jar com/acme/Foo.class com/acme/FooBean.class 2008 JavaOneSM Conference | java.sun.com/javaone | 39
  • 40. Web/EJB Technology Application in JavaTM EE Platform 6 foo.war WEB-INF/classes/ com/acme/FooServlet.class WEB-INF/classes/ com/acme/FooBean.class 2008 JavaOneSM Conference | java.sun.com/javaone | 40
  • 41. EJB in a WAR file Goal is to remove an artificial packaging restriction • NOT to create a new flavor of EJB component EJB component behavior is independent of packaging Full EJB container functionality available 2008 JavaOneSM Conference | java.sun.com/javaone | 41
  • 42. Agenda Overview Pluggability Ease of Development Comet Security Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 42
  • 43. Status Currently in Early Draft Review Public Review in summer of this year Proposed final draft and final release aligned with Java™ EE 6 Early access to bits of implementation to be available via Project GlassFish 2008 JavaOneSM Conference | java.sun.com/javaone | 43
  • 44. Agenda Overview Pluggability Ease of Development Comet Security Status Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 44
  • 45. Summary Lot of exciting things happening in the Java™ Servlet 3.0 API • Pluggability for frameworks • Ease of Development for developers • Comet support to enable modern web 2.0 style applications • Security enhancements to enable programmatic login / logout • Miscellaneous improvements for better developer experience Make the life of framework developers and users much easier Implementation being done in open source as part of GlassFish project 2008 JavaOneSM Conference | java.sun.com/javaone | 45
  • 46. GlassFish Community Open Source, Enterprise Ready & Extendable •GlassFish V3 Tech Preview 2 Available now! • GlassFish Partner Initiative •Modular OSGi architecture – easy to deploy, Develop and Extend •Expanding the ecosystem for •GlassFish V2 – Production Ready partners. ● Fastest open source app server with • Enterprise and Mission Critical Clustering, High Availability, Load Balancing Support sun.com/software/products/appsrvr ● Support for jMaki, Comet, Ajax, Ruby and • GlassFish Unlimited Pricing Groovy •GlassFish ESB •Fixed price, unlimited ● Core SOA functions now embedded in deployments GlassFish •Combine w/ MySQL Unlimited •GlassFish Communications App Server • Tools Integration ● SIP servlet technology for converged •NetBeans and Eclipse services glassfish.org Always free to download, deploy and distribute 2008 JavaOneSM Conference | java.com.sun/javaone | 46
  • 47. For More Information Official JSR Page • http://jcp.org/en/jsr/detail?id=315 JAX-RS – TS 5425 JSF 2.0 – TS 5979 Mailing list for webtier related issues - webtier@glassfish.dev.java.net Rajiv's blog • http://weblogs.java.net/blog/mode 2008 JavaOneSM Conference | java.sun.com/javaone | 47
  • 48. Rajiv Mordani Senior Staff Engineer, Sun Microsystems TS-5415 2008 JavaOneSM Conference | java.sun.com/javaone | 48