0

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.

Rupeshit
  • 1,476
  • 1
  • 14
  • 23

4 Answers4

0

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)

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • In java code I tried to replace trade mark character with ™ but it wont work on server it is working on localhost – Rupeshit May 24 '11 at 11:12
0

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

Community
  • 1
  • 1
Tahir Akhtar
  • 11,385
  • 7
  • 42
  • 69
  • Thanks for reply but I am not able to find way to insert ascii code of trademark symbol. From which character exactly I have to replace because I am just getting square bolck instead of trademark character. – Rupeshit May 27 '11 at 07:49
  • See the updated answer for a link to sample code. This is not jsp but this shouldn't make much difference. – Tahir Akhtar Jun 01 '11 at 17:10
  • Thanks Tahir, but my question is I am getting unknown character from server side then how I replaced that character with "™" ? – Rupeshit Jun 03 '11 at 08:54
0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Then the files are not saved as UTF-8. Check your editor settings. – BalusC May 24 '11 at 12:50
  • Already tried....I am using RAD & I changed editors encoding settings to UTF-8 after that it is working on localhost but its not working on test server. – Rupeshit May 24 '11 at 13:09
  • Already tried? Why didn't you mention that in the question then? It is a pretty important symptom that it works local but not on testserver. – BalusC May 24 '11 at 13:10
0

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.

Rupeshit
  • 1,476
  • 1
  • 14
  • 23