Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I correctly decode unicode parameters passed to a servlet
    text
    copied!<p>Suppose I have:</p> <pre><code>&lt;a href="http://www.yahoo.com/" target="_yahoo" title="Yahoo!&amp;#8482;" onclick="return gateway(this);"&gt;Yahoo!&lt;/a&gt; &lt;script type="text/javascript"&gt; function gateway(lnk) { window.open(SERVLET + '?external_link=' + encodeURIComponent(lnk.href) + '&amp;external_target=' + encodeURIComponent(lnk.target) + '&amp;external_title=' + encodeURIComponent(lnk.title)); return false; } &lt;/script&gt; </code></pre> <p>I have confirmed <code>external_title</code> gets encoded as <code>Yahoo!%E2%84%A2</code> and passed to <code>SERVLET</code>. If in <code>SERVLET</code> I do:</p> <pre><code>Writer writer = response.getWriter(); writer.write(request.getParameter("external_title")); </code></pre> <p>I get <em>Yahoo!â„¢</em> in the browser. If I manually switch the browser character encoding to UTF-8, it changes to <em>Yahoo!<sup>TM</sup></em> (which is what I want).</p> <p>So I figured the encoding I was sending to the browser was wrong (it was <code>Content-type: text/html; charset=ISO-8859-1</code>). I changed <code>SERVLET</code> to:</p> <pre><code>response.setContentType("text/html; charset=utf-8"); Writer writer = response.getWriter(); writer.write(request.getParameter("external_title")); </code></pre> <p>Now the browser character encoding is UTF-8, but it outputs <em>Yahoo!â¢</em> and I can't get the browser to render the correct character at all.</p> <p>My question is: is there some combination of <code>Content-type</code> and/or <code>new String(request.getParameter("external_title").getBytes(), "UTF-8");</code> and/or something else that will result in <em>Yahoo!<sup>TM</sup></em> appearing in the <code>SERVLET</code> output?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload