Hi all,
I got a trouble when I submit the unicode form by ajax.
when I test the submitted url, it gives me the right unicode value for each
parameter I sent. ex: xxxx.do?st1=tốivề&st2=ngàyvề
but when I retrieve it from bean, it was not unicode value :(
this trouble happens only when I submit one form by ajax action, when I do
it with normal struts action, it's okie, I mean I get all unicode values.
I think that there's something wrong when the Struts servlet receive the url
(GET methods)
help me, thanks in advance
bowlkhin,
PS:
*****************************************************
++++ in web.xml, I use SetCharacterEncodingFilter class to convert string to
utf8
<!-- Filter to set character encoding on each request -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<servlet-name>*.vm</servlet-name>
</filter-mapping>
*****************************************************
in velocity.properties:
input.encoding=UTF-8
output.encoding=UTF-8
default.contentType=text/html; charset=UTF-8
*****************************************************
in vm file:
.........
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</header>
......
<form name="searchQuickFormBean"
action="javascript:retrieveURL('$link.setAction('/t/search')',
'searchQuickFormBean','wpm');" >
<table border="0" cellpadding="0" cellspacing="0" width="100%"
id="table3">
<tr>
<td width="20"></td>
<td width="80">
<select size="1" name="searchConstraint.searchType">
<option selected
value="0">[$text.get("guest.index.top_banner.search.select")]</option>
<option
value="1">$text.get("guest.index.top_banner.search.company")</option>
<option
value="2">$text.get("guest.index.top_banner.search.product")</option>
<option
value="3">$text.get("guest.index.top_banner.search.member")</option>
<option
value="4">$text.get("guest.index.top_banner.search.news")</option>
</select>
</td>
<td width="10"></td>
<td width="99">
<input type="text" name="searchConstraint.keyWord" size="17"
maxlength="50" style="font-size: 11px; font-weight: 500; float:left">
</td>
</tr>
</table>
##end simple search
</form>
*****************************************************
below is my ajax.js
function retrieveURL(url,nameOfFormToPost, spanTagName) {
// set name of span tag
curSpanTagName = spanTagName;
//get the (form based) params to push up as part of the get request
url=url+"?noPara=yes"+getFormAsString(nameOfFormToPost);
//Do the Ajax call
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true); //was get
} catch (e) {
alert("Problem Communicating with Server\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}
}
function getFormAsString(formName){
//Setup the return String
returnString ="";
//Get the form values
formElements=document.forms[formName].elements;
//loop through the array , building up the url
//in the form /strutsaction.do&name=value
for ( var i=formElements.length-1; i>=0; --i ){
//we escape (encode) each value
returnString=returnString+"&"+formElements[i].name+"="+formElements[i].value;
}
//return the values
return returnString;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]