• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Servlet
 

 

Statistics

Views

Total Views
460
Views on SlideShare
460
Embed Views
0

Actions

Likes
0
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Servlet Servlet Presentation Transcript

    • Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
    • ServletAbhishek H Menonabhishekmenon121989@gmail.comwww.facebook.com/abhishekmenon.5twitter.com/abhishekmenon121989in.linkedin.com/in/abhishekhmenon
    • Servlet• Is a java programming language class thatused to extend the capabilities of a server.• Can respond to any type of requests, but theyare commonly used to extend the applicationshosted by web servers.
    • Why Servlet is used?• Process or store data that was submitted froman html form• Provide dynamic content such as the results ofa database query• Manage state information that does not existin the stateless HTTP protocol, such as fillingthe articles into the shopping cart of theappropriate customer.
    • Diagram
    • Servlet• In the terms of Java, Servlet is a class in J2EEwhich provides all the functionalities of aserver.• Thus a developer can use Servlet inorder toadd the dynamic content to a web serverusing Java platform.• Servlet is used as a shorthand of HTTP Servlet
    • Servlet• Can be generated automatically from javaserver pages (JSP) by the JavaServer PagesCompiler.• Difference between servlet and JSP is that isthat servlets typically embed HTML inside Javacode, while JSPs embed Java code in HTML.
    • How Servlet works?ReceiverequestSendresponseIsservletloaded?Isservletcurrent?Process requestLoad ServletNOYESNOYES
    • Servlet APIs• Every servlet must implementjavax.servlet.Servlet interface• Most servlets implement the interface byextending one of these classes–javax.servlet.GenericServlet–javax.servlet.http.HttpServlet
    • Generic and HTTP ServletbrowserbrowserserverHTTPserverrequestrequestresponseresponseHTTP ServletGeneric Servletservice()doGet()doPost()service()
    • Generic servlet methods• void init(ServletConfig config)– Initializes the servlet.• void service(ServletRequest req, ServletResponse res)– Carries out a single request from the client.• void destroy()– Cleans up whatever resources are being held (e.g., memory, filehandles, threads) and makes sure that any persistent state issynchronized with the servlets current in-memory state.• ServletConfig getServletConfig()– Returns a servlet config object, which contains any initializationparameters and startup configuration for this servlet.• String getServletInfo()– Returns a string containing information about the servlet, such as itsauthor, version, and copyright.Life cyclemethodsof Servlet
    • Servlet LifecycleInitializationinit()Serviceservice()doGet()doPost()doDelete()doHead()doTrace()doOptions()Destructiondestroy()ConcurrentThreadsof Execution
    • HttpServlet - Methods• void doGet (HttpServletRequest request,• HttpServletResponse response)– handles GET requests• void doPost (HttpServletRequest request,• HttpServletResponse response)– handles POST requests• void doPut (HttpServletRequest request,• HttpServletResponse response)– handles PUT requests• void doDelete (HttpServletRequest request,• HttpServletResponse response)– handles DELETE requests
    • Servlet Request Objects• provides client request information to a servlet.• the servlet container creates a servlet request object andpasses it as an argument to the servlets service method.• the ServletRequest interface define methods to retrieve datasent as client request:– parameter name and values– attributes– input stream• HTTPServletRequest extends the ServletRequest interface toprovide request information for HTTP servlets
    • HttpServletRequest - MethodsEnumeration getParameterNames()an Enumeration of String objects, eachString containing the name of a requestparameter; or an empty Enumeration ifthe request has no parametersjava.lang.String[] getParameterValues (java.lang.Stringname)Returns an array of String objectscontaining all of the values the givenrequest parameter has, or null if theparameter does not existjava.lang.String getParameter (java.lang.String name)Returns the value of a requestparameter as a String, or null if theparameter does not exist.
    • HttpServletRequest - MethodsCookie[] getCookies()Returns an array containing all of the Cookieobjects the client sent with this request.java.lang.String getMethod()Returns the name of the HTTP method withwhichthi request was made, for example,GET, POST, or PUT.java.lang.String getQueryString()Returns the query string that is contained inthe request URL after the path.HttpSession getSession()Returns the current session associated withthis request, or if the request does not have asession, creates one.
    • Servlet Response Objects• Defines an object to assist a servlet in sendinga response to the client.• The servlet container creates aServletResponse object and passes it as anargument to the servlets service method.
    • HttpServletResponse - Methodsjava.io.PrintWriter getWriter()Returns a PrintWriter object thatcan sendcharacter text to the clientvoid setContentType(java.lang.String type)Sets the content type of theresponse being sent to theclient. The content type mayinclude the type of characterencoding used, for example,text/html; charset=ISO-8859-4int getBufferSize()Returns the actual buffer sizeused for the response
    • If this presentation helped you, please visit ourpage facebook.com/baabtra and like it.Thanks in advance.www.baabtra.com | www.massbaab.com |www.baabte.com
    • Contact UsEmarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550Start up VillageEranakulam,Kerala, India.Email: info@baabtra.com