Server-side Technologies in Java

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    5 Favorites

    Server-side Technologies in Java - Presentation Transcript

    1. Web Technologies – Server-side
    2. What’s in store…
      • Basic Server concepts
      • HTTP Request, Response and Session
      • Understanding Servlets
      • The deal with JSP s
      • The quest for scriptless JSPs – Taglibs , JSTL
      • Security, Filters and Listeners
      • Understanding the web application descriptor – web.xml
      • The evolution of Web Application Architecture
    3. R O L E of a S E R V E R
      • Receives the request, finds the resource, returns the response
      • Of course, there’s 404 ! What are the other status codes?
      • Can be the physical m/c [hardware] or web server app [software]
      • Most of the communication is HTTP based
      • Provides a container within which server code can execute
    4. Protocols P R O T O C O L S
      • HTTP is the most commonly used
      • Other supported protocols are FTP, HTTPS, FILE
      • Each of these protocols operate on top of TCP/IP
      • TCP chunks data into blocks and makes sure all of it reaches dest
      • IP underlying protocol to move/route data packets between src & dest
    5. HTTP R E Q U E S T
      • method informs server about the type of request, how the message is formatted
      • GET and POST are most common, but there are others – PUT, HEAD, DELETE, etc
      • Total amount of info through GET is limited
      • Submitted request data is visible with GET. Passwords!
      • Bookmarking of <form> data submission not possible with POST
    6. G E T Request Internals Request Line HTTP Method Path to the resource All the request parameters Protocol version for the request Request headers
    7. P O S T Request Internals Request Line HTTP Method Path to the resource Protocol version for the request Request headers Message body – “payload”
    8. Response Internals Protocol version used by server HTTP Response status code Response headers Text version of status code Body content – HTML or other Mime-type
    9. HTTP S E S S I O N
      • The conversational state
      • Both browsers and servers possess NO short/long term memory!
      • HTTP is stateless !
      • In comes session management –
        • URL rewriting - URL needs to be encoded – response.encodeURL(“…”)
        • Cookie handling
    10. S E R V L E T S …
      • Live to service clients
      • Needs to know what and how to find data in request
      • Send back the response to the browser, or elsewhere
      • The servlet container transforms HTTP Request and Response to HTTPRequest and HTTPResponse objects
      • The container relies on web descriptor to determine which servlet to invoke
    11. S E R V L E T L I F E C Y C L E
      • init – only ONCE when servlet gets loaded
        • So when all does the servlet get loaded ?
      • service – every time a particular servlet is invoked
        • HTTPServlet provides the doGet and doPost methods
      • destroy – when the web application is brought down
      <<interface>> Servlet GenericServlet HTTPServlet YourServletClass
    12. S E R V L E T S – Important Methods
      • HTTPRequest –
        • getParameter(String)
        • get/set Attribute(String, Object)
        • getSession(boolean)
        • getCookies()…
      • HTTPResponse –
        • addCookie()
        • addHeader()
        • setStatus()
        • getOutputStream()
        • getWriter()
    13. J S P – Java Servlet Pages
      • Container converts JSP -> Java source code -> compiles into a Servlet
      • Can directly write Java code in a JSP, but DO NOT!
      • Java code contained within <% javaCodeComesHere; %>
        • Incase of expressions, never end with a semi-colon - <%= expression %>
      • Certain Java objects are available implicitly
        • request, response, out, session, config, application, page, …
      • Taglibs or JSTL are much better options
    14. J S P Structure
      • Non-implicit Java classes can be imported using directive
        • <%@ page import=“org.abc.xyz.*” %>
        • “ ,” can be used to separate multiple imports
      • Scriptlet - <% … %>
      • Directive - <%@ … %>
      • Expression - <%= … %>
      • Comments - <%-- … --%>
      • Declaration - <%! … %>
    15. J S P Lifecycle
      • Container first checks amongst the directives
      • Creates an HttpServlet sub-class
        • In Tomcat, org.apache.jasper.runtime.HttpJspBase , extended
      • Imports are resolved
      • A package declaration – org.apache.jsp.[folderStructure] – is added
      • Builds the service() method - _jspService()
      • The servlet class – JspName_jsp.java – is created
    16. J S P - I M P L I C I T Objects
      • JspWriter – out
      • HttpServletRequest – request
      • HttpServletResponse – response
      • HttpSession – session
      • ServletContext – application
      • ServletConfig – config
      • JspException – exception
      • PageContext – pageContext
      • Object -- page
    17. Scriptless J S P - Taglibs & JSTL
      • Taglibs are powerful – but non-standardised!
      • Multiple vendors – different Taglibs – chaos!
      • Operations requiring scripting – iteration, accessing scoped objects, etc
      • JSTL encapsulates core functionalities related to –
        • Iteration & conditionals [ Core ]
        • XML [ XML ] – useful in case of XML content
        • Database access [ Database ]
        • Internationalised formatting [ Internationalization ]
        • Utility functions [ Functions ]
    18. Inside J S T L
      • Core library – iterations, scope access, conditionals
        • <%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %>
        • <c:set scope=“”>, <c:remove> - set/remove variables in defined ‘scope’
        • <c:forEach var=“” items=“” begin=“” end=“” varStatus=“”> - Iteration
        • <c:if test=“”> - conditional if
        • <c:choose> - condition if-else <c:when test=“”></c:when> <c:otherwise></c:otherwise> </c:choose>
        • <c:import> - including another JSP file, no buffering
    19. Inside J S T L …
      • Expression Language [EL] library – powerful set of functions
        • <%@ taglib prefix=&quot;fn&quot; uri=&quot;http://java.sun.com/jsp/jstl/functions&quot; %>
        • <fn:length>, <fn:toUpperCase>, <fn:toLowerCase>, <fn:substring>, <fn:substringBefore>, <fn:substringAfter>…
        • <%-- truncate name to 30 chars and display it in uppercase --%> ${fn:toUpperCase(fn:substring(name, 0, 30))}
        • <%-- Display the name if it contains the search string --%> <c:if test=&quot;${fn:containsIgnoreCase(name, searchString)}&quot;> Found name: ${name} </c:if>
    20. Inside J S T L
      • Core library – iterations, scope access, conditionals
        • <%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %>
        • <c:set scope=“”>, <c:remove> - set/remove variables in defined ‘scope’
        • <c:forEach var=“” items=“” begin=“” end=“” varStatus=“”> - Iteration
        • <c:if test=“”> - conditional if
        • <c:choose> - condition if-else <c:when test=“”></c:when> <c:otherwise></c:otherwise> </c:choose>
        • <c:import> - including another JSP file, no buffering
    21. The WEB D E S C R I P T O R
      • More famously known as the web.xml
      • Defines almost all aspects of the deployed behaviour of the application
      • Context of web application – the logical root folder of deployed resources
      • <welcome-file-list> - The list of lookup files when context root is accessed
      • <servlet-mapping> - maps URL patterns to servlets
      • <servlet> - maps servlet names to servlet classes
      • <init-parameter> - Servlet specific initialisation parameter
      • <context-param> - Application context parameters
    22. The Evolution of Web Application Architecture
      • Started with the servlets being the centre of the world
      • Then came JSP, but soon all the Java scriptlets ruined it!
      • Separation of Concerns!
      • In came MVC
        • [M]odel - Simple POJOs represent datasets
        • [V]iew – JSPs without any or rare usage of Java scriptlets
        • [C]ontroller – The servlets determined the flow of control
      • Greater configurability and modularity led to MVC2 – Struts2, Spring, etc
    23. Some more Advanced Concepts
      • Listeners – listen to any change events , provide hooks
        • Typically have created and destroyed kind of methods
        • ServletContextListener
        • HttpSessionListener
      • Filters – like a light-weight servlet that doesn’t create its own content
        • Plugs into the request or response handling mechanism
        • Mapped to a particular URL pattern
        • If URL is mapped to servlet – filter will get executed before servlet
        • Typical use – generating user access statistics
    24. R E F E R E N C E S
      • Head First Servlets And JSP
      • JSTL Presentation – Sang Shin, Sun Microsystems
      • Java Boutique
      • Wikipedia
    25.  
    SlideShare Zeitgeist 2009

    + anirvan.majumdaranirvan.majumdar Nominate

    custom

    454 views, 5 favs, 1 embeds more stats

    Covers a wide variety of technologies and solutions more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 454
      • 453 on SlideShare
      • 1 from embeds
    • Comments 0
    • Favorites 5
    • Downloads 0
    Most viewed embeds
    • 1 views on http://static.slidesharecdn.com

    more

    All embeds
    • 1 views on http://static.slidesharecdn.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories