You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Johan Wallinder <wa...@post.utfors.se> on 2004/02/24 19:39:54 UTC

Content type for jsp/html files

Hi.

I've want to make a servlet that can display the source of any jsp/html
file (not the rendered one). 

Basically my code is like this:

*set content type to text/plain
*get PrintWriter object out
*get the fileobject as an inputstream 
*write to the out object
*flush/close

The code is working fine, but viewing the servlet execution in a
browser, the content type is set to text/html which means that all tags
are not displayed (hidden).

How can I override this behavior. If I read a text file everything works
fine. But if the file begins with an <html> tag, the contenttype is set
to text/html. Is this a browser problem? 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Content type for jsp/html files

Posted by Yansheng Lin <ya...@silvacom.com>.
typo: context type should be context type.

-----Original Message-----
From: Yansheng Lin [mailto:yansheng.lin@silvacom.com] 
Sent: Tuesday, February 24, 2004 3:15 PM
To: 'Tomcat Users List'
Subject: RE: Content type for jsp/html files


Totally!  With context type set to text/plain is not going to provent IE doing
something on its own.

The sure fix is to replace all the "<" with "&lt;".


-----Original Message-----
From: Antonio Fiol Bonnín [mailto:fiol.bonnin@terra.es] 
Sent: Tuesday, February 24, 2004 12:41 PM
To: Tomcat Users List
Subject: Re: Content type for jsp/html files


Johan Wallinder wrote:

>Hi.
>
>I've want to make a servlet that can display the source of any jsp/html
>file (not the rendered one). 
>
>Basically my code is like this:
>
>*set content type to text/plain
>*get PrintWriter object out
>*get the fileobject as an inputstream 
>*write to the out object
>*flush/close
>
>The code is working fine, but viewing the servlet execution in a
>browser, the content type is set to text/html which means that all tags
>are not displayed (hidden).
>
>How can I override this behavior. If I read a text file everything works
>fine. But if the file begins with an <html> tag, the contenttype is set
>to text/html. Is this a browser problem? 
>  
>

I'm afraid Internet Explorer is willing to play with you. ;-)

Try adding "nonsense.txt" to your URL, as in:

http://path/to/your/resource?nonsense.txt

IE has a horrible MIME behaviour. Live with it, or trash IE ;-)


Antonio Fiol


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Content type for jsp/html files

Posted by Yansheng Lin <ya...@silvacom.com>.
Totally!  With context type set to text/plain is not going to provent IE doing
something on its own.

The sure fix is to replace all the "<" with "&lt;".


-----Original Message-----
From: Antonio Fiol Bonnín [mailto:fiol.bonnin@terra.es] 
Sent: Tuesday, February 24, 2004 12:41 PM
To: Tomcat Users List
Subject: Re: Content type for jsp/html files


Johan Wallinder wrote:

>Hi.
>
>I've want to make a servlet that can display the source of any jsp/html
>file (not the rendered one). 
>
>Basically my code is like this:
>
>*set content type to text/plain
>*get PrintWriter object out
>*get the fileobject as an inputstream 
>*write to the out object
>*flush/close
>
>The code is working fine, but viewing the servlet execution in a
>browser, the content type is set to text/html which means that all tags
>are not displayed (hidden).
>
>How can I override this behavior. If I read a text file everything works
>fine. But if the file begins with an <html> tag, the contenttype is set
>to text/html. Is this a browser problem? 
>  
>

I'm afraid Internet Explorer is willing to play with you. ;-)

Try adding "nonsense.txt" to your URL, as in:

http://path/to/your/resource?nonsense.txt

IE has a horrible MIME behaviour. Live with it, or trash IE ;-)


Antonio Fiol


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Content type for jsp/html files

Posted by Antonio Fiol Bonnín <fi...@terra.es>.
Johan Wallinder wrote:

>Hi.
>
>I've want to make a servlet that can display the source of any jsp/html
>file (not the rendered one). 
>
>Basically my code is like this:
>
>*set content type to text/plain
>*get PrintWriter object out
>*get the fileobject as an inputstream 
>*write to the out object
>*flush/close
>
>The code is working fine, but viewing the servlet execution in a
>browser, the content type is set to text/html which means that all tags
>are not displayed (hidden).
>
>How can I override this behavior. If I read a text file everything works
>fine. But if the file begins with an <html> tag, the contenttype is set
>to text/html. Is this a browser problem? 
>  
>

I'm afraid Internet Explorer is willing to play with you. ;-)

Try adding "nonsense.txt" to your URL, as in:

http://path/to/your/resource?nonsense.txt

IE has a horrible MIME behaviour. Live with it, or trash IE ;-)


Antonio Fiol

Re: Content type for jsp/html files

Posted by Parsons Technical Services <pa...@earthlink.net>.
Yes, if all browsers played fair and treated thing properly. But IE and some
others have a "mind" of there own. They have been written to handle sloppy
code and thus often don't follow the rules.

Thus we are often forced to work around them.

Doug

----- Original Message ----- 
From: "Johan Wallinder" <wa...@post.utfors.se>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Tuesday, February 24, 2004 5:54 PM
Subject: RE: Content type for jsp/html files


>
> I've already done that. But than I was thinking. Isn't there an easier
> way to display "plan text" files by setting the content type (and not
> encode the content).
>
> -----Original Message-----
> From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net]
>
> Sent: den 24 februari 2004 23:28
> To: Tomcat Users List
> Subject: Re: Content type for jsp/html files
>
>
> Johan,
>
> If the purpose is just to see the code, then you can parse the stream
> and replace each of the <> symbols with a substitute. This will cause
> the browser to see everything as plain text. Parse the stream. If
> character equals < then replace with &lt; If character equals > then
> replace with &gt;
>
> With this your code will display correctly on the screen.
>
> Doug
>
> ----- Original Message ----- 
> From: "Johan Wallinder" <wa...@post.utfors.se>
> To: <to...@jakarta.apache.org>
> Sent: Tuesday, February 24, 2004 1:39 PM
> Subject: Content type for jsp/html files
>
>
> > Hi.
> >
> > I've want to make a servlet that can display the source of any
> > jsp/html file (not the rendered one).
> >
> > Basically my code is like this:
> >
> > *set content type to text/plain
> > *get PrintWriter object out
> > *get the fileobject as an inputstream
> > *write to the out object
> > *flush/close
> >
> > The code is working fine, but viewing the servlet execution in a
> > browser, the content type is set to text/html which means that all
> > tags are not displayed (hidden).
> >
> > How can I override this behavior. If I read a text file everything
> > works fine. But if the file begins with an <html> tag, the contenttype
>
> > is set to text/html. Is this a browser problem?
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Content type for jsp/html files

Posted by Johan Wallinder <wa...@post.utfors.se>.
I've already done that. But than I was thinking. Isn't there an easier
way to display "plan text" files by setting the content type (and not
encode the content).

-----Original Message-----
From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net]

Sent: den 24 februari 2004 23:28
To: Tomcat Users List
Subject: Re: Content type for jsp/html files


Johan,

If the purpose is just to see the code, then you can parse the stream
and replace each of the <> symbols with a substitute. This will cause
the browser to see everything as plain text. Parse the stream. If
character equals < then replace with &lt; If character equals > then
replace with &gt;

With this your code will display correctly on the screen.

Doug

----- Original Message ----- 
From: "Johan Wallinder" <wa...@post.utfors.se>
To: <to...@jakarta.apache.org>
Sent: Tuesday, February 24, 2004 1:39 PM
Subject: Content type for jsp/html files


> Hi.
>
> I've want to make a servlet that can display the source of any 
> jsp/html file (not the rendered one).
>
> Basically my code is like this:
>
> *set content type to text/plain
> *get PrintWriter object out
> *get the fileobject as an inputstream
> *write to the out object
> *flush/close
>
> The code is working fine, but viewing the servlet execution in a 
> browser, the content type is set to text/html which means that all 
> tags are not displayed (hidden).
>
> How can I override this behavior. If I read a text file everything 
> works fine. But if the file begins with an <html> tag, the contenttype

> is set to text/html. Is this a browser problem?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Content type for jsp/html files

Posted by Parsons Technical Services <pa...@earthlink.net>.
Johan,

If the purpose is just to see the code, then you can parse the stream and
replace each of the <> symbols with a substitute. This will cause the
browser to see everything as plain text.
Parse the stream. If character equals < then replace with &lt; If character
equals > then replace with &gt;

With this your code will display correctly on the screen.

Doug

----- Original Message ----- 
From: "Johan Wallinder" <wa...@post.utfors.se>
To: <to...@jakarta.apache.org>
Sent: Tuesday, February 24, 2004 1:39 PM
Subject: Content type for jsp/html files


> Hi.
>
> I've want to make a servlet that can display the source of any jsp/html
> file (not the rendered one).
>
> Basically my code is like this:
>
> *set content type to text/plain
> *get PrintWriter object out
> *get the fileobject as an inputstream
> *write to the out object
> *flush/close
>
> The code is working fine, but viewing the servlet execution in a
> browser, the content type is set to text/html which means that all tags
> are not displayed (hidden).
>
> How can I override this behavior. If I read a text file everything works
> fine. But if the file begins with an <html> tag, the contenttype is set
> to text/html. Is this a browser problem?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org