Vous êtes sur la page 1sur 5

Servlets Web component SW entity providing dynamic web capabilities by running on a server eg servlet and jsp,jdbc Servlet-must be compiled

by the programmer a sinlge process can handle multiple requests by creating thread for each request Jsp-text based doc +java codes -translated into servlets once deployed Web container Execution environment for servlets and jsp manages life cycle and execution of servlets and jsps supports http need not be a part of web server can come as pluggable component of web server eg: tomcat Generic servlet-javax.servlet Http Servlet-javax.servlet.http Servlet life cycle init()-is created only once during servlets life time Service()/called directly rest of the time doXXX() destroy()-called once when the servlet is no longer required Exceptions generally thrown by doget and dopost IOException and ServletException init param not avail to all servlets comes under sevlet tag if the servlet fails to access the initialization parameters it returns null val ues getInitParameter() getParameter() manually convert string to integer if parameter exists but no value, an empty string is returned WAR web components +static web content files=web resources Root file may differ for each server ie web-inf grouping all files makes it poratable manually packaging an application into war file can be acccomplished using Ant tool and Jar tool Ant

uses xml files for creating war files Deploy tool graphical war dist tool with jwsdp creates war based on the information enter by the user into the deploytools wizard and inspectors JAR tool eg: jar cvf webappname.war Tomcat 4.0.3 is the official reference implementaion of servlets 2.3 and jsp 1.2 while jrun -macromedia servletExec-new atlanata are unofficial versions EJbs with servlet ADVANTAGES : Changes in structure multiple clients security

allows changes easier protects the data centrall control for EJB access Servlet access as an intermediatory and handles all the client requests there prevents any direct access to ejbs PortableRemoteObject needed only to ensure that a remote object conforms to its expected class type. The local object type is gu aranteed Exceptions by EJB EJBExep-top level NosuchEntityExceptio CreateException -when cant be instanatiated FinderException-when Ejbs instance cant be found Local Exceptions AccessLocalExp-caller does not have permission NoSuchObjectLocalException-pinpoint Local access errors JNdi Exp NaminExp IncalidAttributeValueExp NamingSecurityExp Remote Exp RemoteException-when call fails due to communication error StubNotFoundException

EJB tags <ejb-link> allows a specific ejb component to be specified for an ejb refernce <ejb-ref> =declares ref a refernce to an Ejb for a servlet common to all web components <ejb-ref-name> <ejb-ref-type> -type , can have value of entity or session <home> specifies fully qualified class name of EJB home interface <remote>-fully qualified class name of ejbs remote interface Forward-Request dispatcher Full Control is passed to the called resource Response data is preserved on the page that is forwarded to, because we use HttpServletRequest Relative urls on the destination page will not always work Control we be passed only if specified Jdbc servlets - not therad safe in init method-database connection is looked up and opened <resourse-ref> <res-ref-name> <res-type> <res-auth> </resourse-ref> Http session interface is found on cookie and url rewriting technology generates unique session Id identifies and extracts particular cookie that stores the session ID Sets suitable expiration time for sessions

Hidden form fields session info can be included in fields and made available to post and ge t data cookies: Stores information about sessions Url rewriting Solution to Http statelessness when browser does not support cookies or when the user has disabled them HttpSession Interface' getSession()-gets the session getSession(true)-new session will be created incase if it does not exists alrea dy getId() getCreationTime() getLastAccessedTime() getMaxInactiveInterval() setMaxInactiveInterval(int interval) interval=in seconds

-ve val reps session never times out invalidate() deactivates the session once the session is timed out /deactivated objs associated with it will be unbound encodeUrl() appends the session information only if url rewriting is enabled otherwise it will be left unaltered encodeRedirectUrl() will be used if sendRedirect() is uesd Filters class has to implement interface filter Filter-comes only in servlet 2.3 and above filter chain-invokes chain of filtered reqs filter config-provides info to filter during init,also used in init() filter defin-obj to dynamically intercept servlet and jsp requests and responses -runs on web server and acts as intermediary between client and servlet/jsp -blocks req and prevents a req resource from being forwarded -invokes req res but modifyes the res before forwarding -invokes req res with modified req info -performs post processing after the servlet has issued a response to alter respo nse headers -should not be used to create responses to reqs.but for transforming reqs and re s -should not be dependent on specific component and should provide universal funs -can config 1/more filters to act on single servl/jsp Func of fiilters locallization tokenin data comp encry auth mime-type chaining cahing logging blocking tracking advantages modularity-resuable codes maintenance-sep high level access code form presenta portablility M() dofilter-has option to block the req by not invoking the next component in the c hain param-req, resp,Filterchain throws-Io excp,ServletExcp <filter> <filter-name> <filter-class>packagename.class name </filter> <filter-mapping>

<filter-name> <servlet-name> <filter-mapping> Listeners-java.util.EventListener -interface servletContextListener-servletContextEvent <listener> <listener-class> </listener>

Vous aimerez peut-être aussi