• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi Please justify it..

 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi please justify it.



OUTPUT:
<p>Welcome Kyarish</p>
U


---------------------------------
EXPECTED OUTPUT WAS:
Welcome Kyarish

U
---------------------------------
As the Writer is estblished using the values supplied to the methods
void setCharacterEcoding(String)
void setContentType(String)
void setContentLength(int)

Changing the values would not be of use, once getWriter() method is called.

It's working fine for void setCharacterEcoding(String) and void setContentLength(int)
but not for void setContentType(String)

Also API says - If obtaining a PrintWriter, this method should be called first.


Regards,
Khushhal
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite clear on what you're asking. The code prints "p" tags, the output consequently contains those, but you were not expecting them?
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf

Actually

response.setContentType("text/html");

is called before

PrintWriter out = response.getWriter();

So, type of output should be html not plain text
as response.setContentType("text/plain;charset=ISO-8859-1"); is called after retrieving the Writer.

So why am i seeing html tags <p> and </p> in output.

Regards,
Khushhal
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting the content type only influences the HTTP header of the same name; it does nothing to the content itself. The code is essentially saying "this is HTML" or "this is plain text", so that the browser can take appropriate action.

Furthermore, something like "<p>" is plain text, because it consists solely of ASCII characters. Interpreting it as HTML gives it special meaning, but that happens in the browser. The server will faithfully output exactly what the code tells it output.
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ulf,

I got it.

Regards,
Khushhal
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic