views:

322

answers:

3

Hi. I have a little problem: I'm writing to response content of the file and return it to the client as an ajax response.
But there occurs html substitution: of > to > etc...
What i have to do to make this substitution off ?

res.setHeader( "Cache-Control", "must-revalidate, post-check=0, pre-check=0" );
res.setHeader( "Pragma", "public" );
res.setContentType( "text/html" );

TIA

update

//    import com.ibm.useful.http.PostData;
        PostData pd = new PostData( req );
        final FileData data;

    try {
        data = pd.getFileData( "sqlFile" );

    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    for ( byte b : data.getByteData() ) {
       buf.write( b );
    }
    res.getWriter().print( buf.toString() );
}

i watched buf.toString() through debugger. it's ok there. substitution goes further. but where...

A: 

This usually happens when html characters (

<, > , "

amongst others) are being escaped. Try setting escape to false or similar. Can't find the api documentation for "com.ibm.useful.http.PostData"

Kennet
And it happened for your markdown also :-)
Ravi Gupta
A: 

Try using below snippet:

res.setContentType("text/html; charset=UTF-8");

Please make sure your database is set to UTF-8 encoding as well, if your using one.

If this doesn't solve, please read this article.

Ravi Gupta
This problem has nothing but also really nothing to do with character encoding.
BalusC
tried this. doesn't worked for me.
Konoplianko
Also refer the article I have added in the answer.
Ravi Gupta
+2  A: 

The HTML special characters are been escaped into HTML entities.

If you are sure that this happened right after you wrote it to the response and right before the response data arrives at the client, then there's possibly a filter in the chain which has escaped the HTML entities for some reason. Check the declared filters in web.xml and adjust the url-pattern if necessary.

BalusC