Question

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...

Was it helpful?

Solution

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.

OTHER TIPS

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"

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top