• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Init Parameter - Answer Reqd.

 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Can someone give me the answer for this question?

Which of the following techniques is likely to return an initialization parameter for a JSP page? (Choose two.)
A.<%= request.getParameter("myParm") %>
B.<% String s = getInitParameter("myParm"); %>
C.<% = application.getInitParameter("myParm") %>
D.<%= config.getInitParameter("myParm"); %>
E.<%= getParameter("myParm") %>
F.<% Object o = config.getParameter("myParm"); %>
G.<% String s = config.getAttribute("myParm"); %>
H.<% String s = getAttribute("myParm"); %>


I am confused here. Which are the answers? I found this question behind David Bridgewater's JSP chapter.
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is D

config.getInitParameter
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Vivek! Can you see a semi-colon inside the EXPRESSION tag. So that is not the answer even.

Even I found all answers to be inappropriate. The explanation given by the book is this:

====
B and D are the correct answers.

D is correct because the config implicit object (which must be available in your JSP page) has a getInitParameter () method that accepts a String for the parameter name and returns a String representing the parameter object.

B is correct because you are in the middle of servlet code, and the servlet you inherit from almost certainly implements the ServletConfig.getInitParameter () method.

A is incorrect because the parameters you retrieve from requests are tied to the request, usually from fields on an HTML form � so have nothing to do with servlet (JSP) initialization parameters.

C is incorrect because while application does have a getInitParameter () method, the parameter values returned are for the ServletContext (i.e., the web application as a whole).

E is incorrect because there is no getParameter () method available in the generated servlet. F is incorrect because config's method for returning servlet parameters is getInitParameter (), not getParameter. G and H are incorrect because there are no attribute methods associated with ServletConfig or servlets directly�and besides, attributes are not parameters.
====

I can atleast accept D WITHOUT the semi-colon. Can someone explain B?
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops !!

I missed the semicolon ....but I think it is accidental ..
You will not see such mistakes in Sun exam

Also B does not seem to be the correct solution ....
The container's implementation of HttpJspPage interface might not implement ServletConfig ( which is implemented by GenericServlet )
As the answer says that "it is almost certain" ..but not as per spec..
[ November 22, 2006: Message edited by: Vivek Pandey ]
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the config object in a JSP page.


But I admit is a messed up question, I hope I dont get such questions on the exam.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic