You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by red phoenix <ro...@gmail.com> on 2006/10/05 18:46:08 UTC
Struts Encode question
I want to get a value from a JSP in Action,like follows:
/*jsp*/
<%@ page contentType="text/html;charset=gb2312" %>
<html:text property="ex"/>
....
And I input a Chinese Word in ex area,then I get the ex value from a
Action,like follows:
/*Action*/
public ActionForward execute(ActionMapping mapping,ActionForm
form,HttpServletRequest request,HttpServletResponse response) throws
Exception {
request.setCharacterEncoding("gb2312");
String ex=request.getParameter("ex");
....
But I find ex don't show propertly,it should show right Chinese word,but it
shows ???????í?±,I use DynaActionForm,like follows:
<form-bean
name="tt"
type="org.apache.struts.action.DynaActionForm">
form-property
name="ex"
type="java.lang.String"/>
...
Why struts don't show propertly? How to show Chinese Word in Struts Action?
Thanks.
Re: Struts Encode question
Posted by Laurie Harper <la...@holoweb.net>.
red phoenix wrote:
> I want to get a value from a JSP in Action,like follows:
> /*jsp*/
> <%@ page contentType="text/html;charset=gb2312" %>
> <html:text property="ex"/>
> .....
>
> And I input a Chinese Word in ex area,then I get the ex value from a
> Action,like follows:
> /*Action*/
> public ActionForward execute(ActionMapping mapping,ActionForm
> form,HttpServletRequest request,HttpServletResponse response) throws
> Exception {
> request.setCharacterEncoding("gb2312");
> String ex=request.getParameter("ex");
> ....
>
> But I find ex don't show propertly,it should show right Chinese word,but it
> shows ???????í?±,I use DynaActionForm,like follows:
> <form-bean
> name="tt"
> type="org.apache.struts.action.DynaActionForm">
> form-property
> name="ex"
> type="java.lang.String"/>
> ...
>
> Why struts don't show propertly? How to show Chinese Word in Struts Action?
The call to setCharacterEncoding() looks suspicious to me; I don't think
that should be necessary. You have the character encoding declared in
the JSP page directive, which is good; you may also need to add a
meta-equiv content type tag to your page (in the HTML HEAD section) to
help the browser determine the character encoding to use.
Also be wary of displaying non-ASCII string values with e.g.
System.out.println(); the console output may be misleading if it's using
the wrong character encoding. Test your 'ex' variable's value against a
known-good string constant to verify it rather than relying on printing it.
HTH,
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org