1.页面上有这样的代码基本就行!
<%
request = new com.nec.jp.orteus.struts.upload.ParameterizedRequestWrapper(request);
Locale locale = ServerProperties.getUserLocale(request);
String lang = locale.getLanguage();
ResourceBundle rbValidationMessages = ResourceUtil.getResourceBundle("validation-messages", locale);
response.setHeader("Content-Type", "text/html; charset=" + ServerProperties.getJspCharset(lang));
response.setContentType("text/html; charset=" + ServerProperties.getJspCharset(lang));
%>
2.
使用filter做统一转码,修改web.xml,新加RequestEncodingFilter
filter:
package filters.http;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
public class RequestEncodingFilter implements Filter {
public RequestEncodingFilter() {
}
public void init(FilterConfig config) throws ServletException {
encoding = "utf-8";
String enc = config.getInitParameter("encoding");
if (enc != null && enc.length() > 0)
encoding = enc;
}
public void destroy() {
}
/**
*
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
private String encoding;
}
web.xml
<filter>
<filter-name>requestEncodingFilter</filter-name>
<filter-class>filters.http.RequestEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>requestEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>