开发者

Handling special characters with Java and Struts 1.1

Problem:

A form is submitted with a text box on it. I enter a string with the (Registered Trademark) character in it using开发者_运维技巧 alt+0174. The (R) symbol displays in the browser correctly.

I hit submit, with a breakpoint on BaseTilesRequestProcessor (earliest possible spot that I know of to inspect the request)

If I dig into the request and find the value corresponding to the text box, it has my string with the (R) symbol in it, but immediately before the (R) it has a weird character: Â

Before I submitted this question I found the answer here: http://ianpurton.com/struts-utf-8-and-form-submissions I used that technique and it worked correctly. So my question is, why does this work? I checked request.getCharacterEncoding() before this filter was applied and it was null. What sets this property? The browser doing the submission?

Thanks!


Yes, the browser could set this property during submission, but as the link you found correctly pointed out, most browsers don't set this by default. As a result, you get whatever the default in Struts 1 is, which clearly isn't UTF-8. The fact that you got NULL when you checked getCharacterEncoding() confirms that the browser isn't sending any such header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜