You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Vjeran Marcinko <vj...@tis.hr> on 2005/01/31 13:37:57 UTC
How to set content type for plain/text generation
Hi everyone.
Is it possible to set ContentType "text/plain" inside HTTP response?
Among bunch of velocity screens for generating text/html pages, I want one
screen to generate text/plain content.
Thus as usual, I created my TextGenerator.vm template with content, and
TextGenerator.java class as this :
public class TextGenerator extends VelocityScreen {
protected void doBuildTemplate(RunData data, Context context) throws
Exception {
HttpServletResponse resp = data.getResponse();
resp.setHeader("Content-Type", "text/plain");
}
}
There are 2 problems :
1. I had to create TextGenerator.vm layout template inside modules/layouts
directory, that contains only following :
$screen_placeholder
thus this screen wouldn't be placed inside usual Default.vm for other HTML
screens. Is there some more elegant way ?
2. More serious - generated stuff didn't have ContentType set to
"text/plain" but "text/html" (I can see that in page details in my Firefox)
?! How can I set it?
Thanx,
Vjeran
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.2 - Release Date: 28.1.2005
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: How to set content type for plain/text generation
Posted by Vjeran Marcinko <vj...@tis.hr>.
----- Original Message -----
From: "Jeffery Painter" <pa...@kiasoft.com>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Monday, January 31, 2005 2:06 PM
Subject: Re: How to set content type for plain/text generation
> On Mon, 31 Jan 2005, Vjeran Marcinko wrote:
> > There are 2 problems :
> > 1. I had to create TextGenerator.vm layout template inside
modules/layouts
> > directory, that contains only following :
> > $screen_placeholder
> > thus this screen wouldn't be placed inside usual Default.vm for other
HTML
> > screens. Is there some more elegant way ?
> > 2. More serious - generated stuff didn't have ContentType set to
> > "text/plain" but "text/html" (I can see that in page details in my
Firefox)
> > ?! How can I set it?
> >
> > Thanx,
> > Vjeran
> >
> // plain text screen - set headers etc.
> public class TextScreen extends VelocityScreen {
>
> private static String CONTENT_TYPE = "text/plain";
>
> public void doBuildTemplate(RunData data, Context context) {
> data.setLayout(null);
> data.setContentType(CONTENT_TYPE);
>
> HttpServletResponse resp = data.getResponse();
> resp.setHeader("Content-Type", CONTENT_TYPE);
> }
> }
Thanx man. Though only the second (more important) problem was solved. I
still had to have layout .vm file containing only $screen_placeholder to be
able to generate page. Otherwise, it gave me some corrupted stuff...
RunData.setLayout(null) obviously doesn't work for this.
-Vjrean
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.2 - Release Date: 28.1.2005
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: How to set content type for plain/text generation
Posted by Jeffery Painter <pa...@kiasoft.com>.
On Mon, 31 Jan 2005, Vjeran Marcinko wrote:
> Hi everyone.
>
> Is it possible to set ContentType "text/plain" inside HTTP response?
> Among bunch of velocity screens for generating text/html pages, I want one
> screen to generate text/plain content.
> Thus as usual, I created my TextGenerator.vm template with content, and
> TextGenerator.java class as this :
>
> public class TextGenerator extends VelocityScreen {
>
> protected void doBuildTemplate(RunData data, Context context) throws
> Exception {
> HttpServletResponse resp = data.getResponse();
> resp.setHeader("Content-Type", "text/plain");
> }
> }
>
> There are 2 problems :
> 1. I had to create TextGenerator.vm layout template inside modules/layouts
> directory, that contains only following :
> $screen_placeholder
> thus this screen wouldn't be placed inside usual Default.vm for other HTML
> screens. Is there some more elegant way ?
> 2. More serious - generated stuff didn't have ContentType set to
> "text/plain" but "text/html" (I can see that in page details in my Firefox)
> ?! How can I set it?
>
> Thanx,
> Vjeran
>
try this screen class.
// plain text screen - set headers etc.
public class TextScreen extends VelocityScreen {
private static String CONTENT_TYPE = "text/plain";
public void doBuildTemplate(RunData data, Context context) {
data.setLayout(null);
data.setContentType(CONTENT_TYPE);
HttpServletResponse resp = data.getResponse();
resp.setHeader("Content-Type", CONTENT_TYPE);
}
}
--
Thank you,
Jeffery Painter
2431 Reunion Meadows Lane
Apex, NC 27539
voice: 919.321.0378
- --
painter@kiasoft.com http://jeff.kiasoft.com
PGP FP: 9CE8 83A2 33FA 32B1 0AB1 4E62 E4CB E4DA 5913 EFBC
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE/qEQE5Mvk2lkT77wRAnMJAJ9vJ6qOkg/mvqqIpz7troCEQJ8bFACglu/U
YNXabx7DZOV2Hd9LwSTmGpY=
=dWiu
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org