JSP中的页面编码

I am having two jsp say "first.jsp" and "second.jsp" which is included in "first.jsp". I wanted to display trade mark symbol in jsp so I used

  <%@ page pageEncoding="UTF-8"%>

in "first.jsp" which is working fine when first time page is loading. But when I am invoking ajax request then result is coming in "second.jsp" which is included in "first.jsp" and this time trade mark symbol is not displaying properly. It displays some block instead of trade mark symbol.

When I saw viewSource there I got symbol displaying properly.

I also tried using content-type but still no luck.

EDITED

After changing editors encoding setting to UTF-8 it is working on localhost but fails on test server.

Any help will be appreciated.

You could use the &trade; entitity, then it should be displayed regardless of encoding.

(but I agree it would be better to get the encoding working correctly)

You don't need to have "UTF-8" encoding to show copyright character. Simplest solution to your problem is to insert ascii code of copyright symbol using HTML escape sequence. For your case, that would be &#169;.

You can easily find a list of all character codes on web (here, for example).

Also you can find code that does HTML escaping for you. Just pass a string and get back a string with all characters escaped correctly.

See this question: Recommended method for escaping HTML in Java


EDIT

See this link for a running sample

You need to put

<%@ page pageEncoding="UTF-8" %>

on every JSP. Not only the master JSPs, but also the include JSPs and JSPs which are abused as ajax response servlets.

As in the question I mentioned that In one JSP (first.jsp) I am including another jsp say second.jsp in the javascript using "innerHtml()" and that is the point where problem was there.

I replaced that part with JQueries "html()" function. And it WORK for me. The reason behind is that as innerHtml() doesnt execute the scripting code where as JQueries html() function executing scripting code.

So replacing innerHtml() function with Jqueries html() function to add another jsp did the trick for me.