Web Component Developer for J2EE Platform 1.4

Posted on
Like what you see? Share it.Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone

Objective : The Structure and Deployment of Web Applications
SubObjective : * Using the HttpServletRequest interface, write code to retrieve HTML form parameters from the request, retrieve HTTP request header information, or retrieve cookies from the request

Single Answer Multiple Choice

 

You have created two different JavaScript files that will be executed depending on the type of browser used to access your Web application. You want to ensure that the appropriate JavaScript file is sent to the client’s browser. Which method call should you use to retrieve the browser type from the request header?

 

 

  1. request.getParameter()
  2. request.getInitParameter()
  3. request.getHeader(“User-Agent”)
  4. request.getHeader(“Browser-Type”)

 

 

 

Answer:
C. request.getHeader(“User-Agent”)

Tutorial:
You should use the request.getHeader(“User-Agent”) method call to retrieve the browser type from the request header. This method call returns the user agent that generated this request. The user agent may be a browser or another program. If it is a browser, the value will contain the name of the browser. If it is another program, the value will contain the name of the program as defined by the developer of the program.

 

The request.getParameter method is used to obtain parameter values from a form submitted by the end user.

 

The request.getInitParameter method is used to obtain initialization values from the deployment descriptor of a Web application.

 

The getHeader method cannot accept the parameter Browser-Type. There is no such standard header defined by any specification. However, it could be a custom header. In such a scenario, the getHeader method cannot contain the browser type information by convention.

 


Objective: The Web Container Model
SubObjective : For the ServletContext initialization parameters: write servlet code to access initialization parameters; and create the deployment descriptor elements for declaring initialization parameters.
Multiple Answer Multiple Choice

 

Which two method calls using the ServletContext interface will facilitate access to a file named kaplandata.bin stored in the /doc-root/kaplan/docs directory? (Choose two.)

 

 

  1. getURL(“/doc-root/kaplan/docs/kaplandata.bin”)
  2. getResource(“/doc-root/kaplan/docs/kaplandata.bin”)
  3. getAttribute(“/doc-root/kaplan/docs/kaplandata.bin”)
  4. getServletContextName(“/doc-root/kaplan/docs/kaplandata.bin”)
  5. getResourceAsStream(“/doc-root/kaplan/docs/kaplandata.bin”)

 

 

 

 

 

Answer:
B. getResource(“/doc-root/kaplan/docs/kaplandata.bin”)
E. getResourceAsStream(“/doc-root/kaplan/docs/kaplandata.bin”)

Tutorial:
The getResource(“/doc-root/kaplan/docs/kaplandata.bin”) method call will return a URL to a file named kaplandata.bin stored in the /doc-root/kaplan/docs directory. The getResource(java.lang.String path) method of the ServletContext interface returns a java.net.URL object. The getResourceAsStream(“/doc-root/kaplan/docs/kaplandata.bin”) method call will facilitate access to the /doc-root/kaplan/docs/kaplandata.bin file. The getResourceAsStream(“/doc-root/kaplan/docs/kaplandata.bin”) method call will return the /doc-root/kaplan/docs/kaplandata.bin file as a java.io.InputStream object.

 

The getURL(“/doc-root/kaplan/docs/kaplandata.bin”) method call is incorrect because the ServletContext interface does not have a getURL method.

 

The getAttribute(“/doc-root/kaplan/docs/kaplandata.bin”) method call will not facilitate access to a file named kaplandata.bin stored in the /doc-root/kaplan/docs directory. The getAttribute(java.lang.String name) method returns the attribute associated with the specified name.

 

The getServletContextName(“/doc-root/kaplan/docs/kaplandata.bin”) method call will not facilitate access to a file named kaplandata.bin stored in the /doc-root/kaplan/docs directory. The getServletContextName method returns the name of the Web application associated with the ServletContext object as specified in the deployment descriptor.

Reference:
1. Java Servlet Specification Version 2.4, javax.servlet, SRV.14.2 The javax.servlet package, SRV.14.2.8 ServletContext
2. Java 2 Platform Enterprise Edition, v 1.4 API Specification, Interface ServletContext, http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html

 


Objective: The Web Container Model
SubObjective : * For the fundamental servlet attribute scopes (request, session, and context): write servlet code to add, retrieve, and remove attributes; given a usage scenario, identify the proper scope for an attribute; and identify multi-threading issues associated with each scope.
Single Answer Multiple Choice

 

You are developing a Web application in which you are required to access an object by using EL that displays the number of visitors for the application. Which option should you use to access the object?

 

 

  1. You are visitor number: ${requestScope.count}
  2. You are visitor number:${pageScope.count}
  3. You are visitor number:${sessionScope.count}
  4. You are visitor number:${applicationScope.count}

 

 

 

Answer:
D. You are visitor number:${applicationScope.count}

Tutorial:
You should use You are visitor number: ${applicationScope.count}. The applicationScope implicit object provides reference to the application context. The applicationScope.count implicit variable accesses the object count and displays the value of count to the user. You can also access the value of count by using the syntax ${applicationScope[‘count’]}.

 

The option that uses the requestScope implicit object is incorrect because the applicationScope implicit object i

Like what you see? Share it.Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone
cmadmin

ABOUT THE AUTHOR

Posted in Archive|

Comment: