Likes

WCD-LAB @HOME 5-Ans 1

Section : Container Facilities for Servlets and JSPs (1 of 2 )


1. Investigate the deployment descriptor and the container's servlet support.



                         INVESTIGATE PROJECT USING WEB.XML
1.Create a new Java Web project named
 2.Create a Servlet .Accept thedefault name new Servlet,and place
      it in the package lab.click Next
3.Select the checkbox Add information to deployment descriptor(web.xml).
4.Modifythe URL pattern(s)field of the table labeled Initalization/*.
5.click on the New buttom to the right of thetable labeled Initialization
   parameters.types into the newly created row of the table in the values keyname
    and Data value under the headingname and Value respectively.
6.Click Finish.
7.Notice that under the project folders web pages->WEB-INF there is a new
   node namedweb.xmlDouble click on the element.
8.From the editor pane,sekect the General tab,then open the Contex Parameters
   region.(Click on the plus sign).
9.Select Add...in the Context Parameter region,enter a parameter name and a
    value.
10.Select XML at the topof the editor window,towardthe right hand end.you
     should see an XML file someWhat like this:
        1<?xml version="1.0" encoding="Utf-8"?>
         2<web-app[......]>
         3<context-param>
          4 <param-value>My parameter value</param-name>
          5 <param -value>My parametervalue</param-value>
          6 </context-param>
         7 <servlet>
         8 <servlet-name<New Servlet</Servlet-name>
       9 <servlet-
          class>s1314m5.lab.NewServlet</servlet-class>
      10 <init-param>
      11 <param-name><keyName</param-name>
      12 <param-value>Data value</param-value>
       13</init-param>
      14 </servlet>
      15 <servlet-mapping>
       16 <servlet- name>NewServlet/*</url-pattern>
       17<url-patterm>/pathToServlet/*</url-pattern>
      18 </servlet-mapping>
       19 <session-cofig>
       20 <session-timeout>
       21 30
       22 </session-timeout>
      23</session-config>
     24 </web-app>
11.Examine the XML file and determine how a triggeringURL is matched to the
      servlet class that must run in response to that URL.
12.Examine the XML file and determine how the Key-value pairs you specified
     are represented.Note also how one couple is associated specifically with the
     servlet,while-the other is at almost the top level of the XML structure andis
   outside the servlet definition.

Task -code the servlet to use the Configuration
 information
 1.Edit the sour File,Writing your code in the processRequest()method
     that has been added by NetBeans.
  2.Extract areference to the ServletContext object.
 3.Store the servlet context in a variable.
 4.Using the servlet context reference,locatedthat you think might
    provide access to a logging to a logging facility.using this method,write amessage to the
    web-container'slogging strem that indicates that the servlet has been invoked
    and output the time invocation.
5.Using the same servlet context referance,determinehow you can obtain the
    context parameter that you stored in the web.xml file.Recall from the lecture
   that this is referred to in thr APIs as an initparameter.As beforNet Beans
    typingcomplention can be used to help.
6.Output completion can be used to help.
7.Extract the value of the servlet initization parameter.Notice that this value is
    extracted directiy from the Httpservlet object(this).
8.Write the name and value of the parameter to the log stream.
9.Create a minimak HTMl page so that the servlet will generate somevisible
   output an thebrowser.Consider including the current data and time here too.

    prapare the index page and Run the Application
1.Edit the index.jsp file of the project.Create a link in it .That should jump
   to path Toserl=velt /blah.
2.run the Program.
3.Look at the GlassFish v3 Dimain tabs.one shows the buliding and
    deployement of the application.the other shows the output from
    the logging request.
4.Determine that the key/value pairs inthe logging output are correct.

No comments: