I've create GET method action Page with apache struts 2.1.8.1.
I'm making a page in encoding UTF-8.
struts action is setter value.
POST method 's setter value is encoding UTF-8.
but
GET method 's value is encoding ISO-8859-1.
This trouble resolved this Action setter.
but When GET was performed and went on POST.
The value is Incomplete.
Fundamentally, would there be a way to correct a change in a character string
besides this way?
web.xml:
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
java :
action:
public class SampleAction extends ActionSupport{
public String execute(){return SUCCESS;}
public void setData(String data){
if(ServletActionContext.getRequest().getMethod().equals("GET")){
try {
this._data = StringUtils.encoding(data);
} catch (UnsupportedEncodingException e) {
}
}else{
this._data = data;
}
}
public String getData(){return _data;}
}
class:
public class StringUtils {
static public String encoding(String str) throws UnsupportedEncodingException {
return new
String(str.getBytes(ServletActionContext.getResponse().getCharacterEncoding()),ServletActionContext.getRequest().getCharacterEncoding());
}
}
jsp Page:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
GET <form method="GET" >
<input name="data" value="日本語"/>
<input type="submit" />
</form>
POST <form method="POST" >
<input name="data" value="日本語"/>
<input type="submit" />
</form><br />
<s:property value="data"/>
</body>
</html>
thank you.
--
kou <[email protected]>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]