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..?
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 ?
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.
Joined: Jul 04, 2002
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.
Joined: Jul 15, 2002
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