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

- --
[EMAIL PROTECTED]                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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to