• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

res.setContentType(???????)

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want a string str="<h1>hello</h1>"; to display in two ways using servlets at the client side.
such that one way it should display as text/plain
and secondly text/html .
how could this be accomplished..?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
res.setContentType("text.html");
// This means that the content type which you would like to publish is either text or html..
if String str="<b>yxz</b>";
s.o.p.ln(str); >> this will give the o/p in the browser YXZ but in bold, it will not display as txt untile unless you read it out from a file of txt extension.
But this kinda thing is not even possible in mail servers as well, If at all you want to send a email and wish that it should appear as HTML for people whose server's can recognize ContentType as HTML and whose servers doesnt recognize this should be appear as simple text mail.
This can be acheived by editing two mails one in http and other in txt format and when you send the request on their server first recognize the ContentType on the server and then choose either HTML or txt (logically pgm) to serve them depending on th features they support.
>> But I think still your question is in complete as you never mention whats happening at the client end ?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
res.setContentType("text.html");
// This means that the content type which you would like to publish is either text or html..

Type - should be text/html, and it is a registered content type. It does not mean 'text or html' it means 'the response is text, html specifically' as opposed to 'text/plain', 'text/xml' etc.
s.o.p.ln(str);
>> this will give the o/p in the browser YXZ but in bold, it will not display as txt untile unless you read it out from a file of txt extension.

I'm assuming s.o.p is System.out.println (s.r.k, please don't abbreviate like this, it causes confusion), and this is incorrect. You want to get an output to the client via either response.getOutput() or reponse.getWriter(). Getting a Writer is easire since you are returning text.
But this kinda thing is not even possible in mail servers as well...
I think we're getting off topic here. Mail has not been mentioned till this point.
My take on the questions was that given a string you wanted to display it as plain text and as bold text, but as a single response.
A response can have only one content-type, so you would set the content type as 'text/html' since this satisfies both, then add the HTML 'mark up' to print the text in bold.
Then again I might be completely off track too.

Dave
 
manju latha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam sorry to say again,
i want this string
String str=" <h1>hello</h1> ";
to print first time as it is (text/plain)
but second time without tags (text/html)
using servlets..!
thanx.
 
s.r.k.reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Dave,
Thanks for the comments!, well coming to the abbreviati....I apologise. May be beginner's might get confused.
text/plain, text/html etc.. I very well know that they are registered types.
The question was
String str="<b>hhhhh</b>";
Can't this be printed as html as well plain text, isn't it.
DAVE>>>>>'text/html' since this satisfies both
SRK>>>>>>This means that the content type which you would like to publish is either text or html..
I meant the same thing brother, well coming to the point of explaining about the mail server. I just gave a example, which I experienced.
Good Luck Nxt T
> <<<< ??? THINK ABOUT THIS
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For text: use a content type string of "text/plain"
For html: use a content type string of "text/html"
Cheers, Neil
 
Do not set lab on fire. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic