• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in setHeader Method

 
Karthik Rajendiran
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I have doubt in setHeader method mentioned in the HFSJ [ Exam at the end of the chapter 4
Question 4

How would you set a header named 'CONTENT-LENGTH in the HttpServletResponse object?

a. res.setHeader(CONTENT-LENGTH, "numBytes");
B. res.setHeader("CONTENT-LENGTH","numBytes");
c. res.setStatus(1024);
d. res.setHeader("CONTENT-LENGTH",1024);

Answer was B.

My question is, the argument for the setHeader of type string. Value of the Header is an integer stored in a string datatype [Ref: It is mentioned earlier inside the chapter 4" for using getIntHeader() method illustration)

But in our example, the B could be syntactically correct but doesnt find useful. If the Option B could be like this

res.setHeader("CONTENT-LENGTH","100"); // 100 or any number could be correct for that matter.

or
String s = new String("100");
res.setHeader("CONTENT-LENGTH",s);

could also be correct.

Can anyone justify whether my argument is rite or wrong

Thanks
karthik
 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello Friends,
I have doubt in setHeader method mentioned in the HFSJ [ Exam at the end of the chapter 4
Question 4

How would you set a header named 'CONTENT-LENGTH in the HttpServletResponse object?

a. res.setHeader(CONTENT-LENGTH, "numBytes");
B. res.setHeader("CONTENT-LENGTH","numBytes");
c. res.setStatus(1024);
d. res.setHeader("CONTENT-LENGTH",1024);

Answer was B.

My question is, the argument for the setHeader of type string. Value of the Header is an integer stored in a string datatype [Ref: It is mentioned earlier inside the chapter 4" for using getIntHeader() method illustration)

But in our example, the B could be syntactically correct but doesnt find useful. If the Option B could be like this

res.setHeader("CONTENT-LENGTH","100"); // 100 or any number could be correct for that matter.

or
String s = new String("100");
res.setHeader("CONTENT-LENGTH",s);

could also be correct.

Can anyone justify whether my argument is rite or wrong

Thanks
karthik


String s = "E";
response.setHeader("CONTENT-LENGTH", s);
is syntactically perfectly valid.
So is
response.setHeader("CONTENT-LENGTH", "E");

Of course, in practice, you would probably want to pass a String that evaluates to a number.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic