![]() |
JBridge: Certification Question Of The Day |
| JBridge Home >> Certification Questions >> Today's Question | Tuesday 6th May 2003 |
|
What will be the outcome of placing the following code in a servlet’s
doGet method? String s = request.getHeaders(“Accept”); PrintWriter out = response.getWriter(); out.write(s); A When a browser makes a request of the servlet, output like the following is seen in a single line on the resulting web page: image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint,
application/msword, application/x-shockwave-flash, */*
B The code will not compile. C When a browser makes a request of the servlet, output like the following is see on separate lines in the resulting web page: image/gif image/x-xbitmap image/jpeg … more similar lines … */* D An IOException is thrown on accessing the servlet. E A browser error occurs because the resulting web page is not in proper HTML format. F An IllegalArgumentName is thrown because “Accept” is not a valid HTML header field. Page down for the answer... The AnswerThe answer is B – the code will not compile. The reason is that
request.getHeaders(String name) returns an Enumeration; it’s the method
request.getHeader(String name) that returns a String. |
EMail: dbridgewater@jbridge.co.uk
Phone: +44 (0)1943 877414
Fax: +44 (0)1943 877414
Mail: David
Bridgewater, Willow Dene, Bradford Road, Menston, Ilkley, West Yorkshire, LS29
6ED, UK
Copyright © 2003 David Bridgewater. All rights reserved.