wood burning stoves*
The moose likes Servlets and the fly likes text/html & text/plain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "text/html & text/plain" Watch "text/html & text/plain" New topic
Author

text/html & text/plain

Grace Lo
Greenhorn

Joined: May 03, 2001
Posts: 12
Hi,
I am using XML and XSL with xalan to show a DOM tree from a browser.
I would allow users to pick eith HTML or plain format at run time.
By using response.setContentType("text/plain" );
or response.setContentType("text/html" );
seems look the same from my browser.
Do I need to write different XSL files like taking out all html tags?
Thanks,
Grace

Grace
Jayson Falkner
Author
Ranch Hand

Joined: May 07, 2001
Posts: 57
Yes.
Just because you set the content type to "text/plain" doesn't mean that HTML tags will be stripped out for you.
Jayson Falkner
V.P./CTO, Amberjack Software LLC
Jayson@jspinsider.com
www.jspinsider.com
[This message has been edited by Jayson Falkner (edited May 10, 2001).]


Jayson Falkner<br />jayson@jspinsider.com<br />Author of <a href="http://www.jspbook.com" target="_blank" rel="nofollow">Servlets and JavaServer Pages; the J2EE Web Tier</a>
Grace Lo
Greenhorn

Joined: May 03, 2001
Posts: 12
I try to take out all html tag from xsl file but it gave me error message as following
Invalid at the top level of the document. Line 1, Position 39
<?xml version="1.0" encoding="UTF-8"?>

What did I do wrong?

Grace
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Your problem has nothing to do with HTML tags. If the content type is "text/plain", the browser will display whatever you send as plain, uninterpreted text. If you send HTML, you will see the HTML source.
The problem is probably that you set a "text/plain" content type in your JSP, that is before it gets fed through Xalan. Actually, Xalan determines its own output content type. You can control this - how else? - using the XSL template. The tag controlling this is <output/>. You use it directly inside the <stylesheet> (or <transform> ) element.
<output method="text"/> should produce plain text output. If you want a MIME type other than "text/plain", add a "media-type" attribute, e.g. media-type="text/chocolate". You can also use an "encoding" attribute to indicate the character encoding used.
<output method="html"/> should produce HTML output. Again you can specify a MIME type and/or encoding. In addition, you can specify a document type attribute, e.g. doctype-system="html3.2.dtd". This should cause Xalan to emit a <!DOCTYPE> tag in the HTML output.
This means that you would create two stylesheets, each with a different <output/> tag. I assume your XML is supposed to specify the content, the stylesheets determine how it is rendered. Text and HTML are quite different ways to render your content; it makes sense to use separate stylesheets for them.
- Peter

[This message has been edited by Peter den Haan (edited May 10, 2001).]
Grace Lo
Greenhorn

Joined: May 03, 2001
Posts: 12
It is working!!!
Thanks a lot!
 
Don't get me started about those stupid light bulbs.
 
subject: text/html & text/plain
 
Similar Threads
Reading a text file on Linux machine
Using response.setcontenttype
text/plain & text/html
Doubts regarding request and response objects.
problem with download dialog box