RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
struts中文的解决
  • 作者:zhaozj
  • 发表时间:2020-12-23 10:54
  • 来源:未知

最近发现在struts的配置文件中配置一个全局的控制就OK了<controller nocache="true" inputForward="true" maxFileSize="2M"   contentType="text/html;charset=gb2312"/>一:国际化的解决方法:1.拷贝ApplicationResources.properties为文件:ApplicationResources_zh.properties2.修改ApplicationResources_zh.properties为中文3.在应用到的JSP中使用ISO_8859_1<%@?page?contentType="text/html;?charset=ISO_8859_1"%>搞定~~~~~~~注意ISO_8859_1,?不要拼错了哦。^O^如果是ISO-8859-1就不成啦~~~验证发现ISO8859-1也成~~~~~~~~~~~~~~~~~~~~~~~~~~

二:从数据库中取数据的解决办法:只要在应用到的JSP中使用gb2312就可以

三:请求的解决办法:加过滤器,如下: ??? Request Filter ??? view.util.RequestFilter ??? ????? encoding ????? UTF-8 ??? ??? ????? ignore ????? true ??? ? ? ??? Request Filter ??? action ? package view.util;

import javax.servlet.*;import java.io.IOException;

public class RequestFilter implements Filter {

??? protected String encoding = null;

??? protected FilterConfig filterConfig = null;

??? protected boolean ignore = true;

??? public void destroy() {

??????? this.encoding = null;??????? this.filterConfig = null;

??? }

??? public void doFilter(ServletRequest request, ServletResponse response,???????????????????????? FilterChain chain)??? throws IOException, ServletException {

??????? if (ignore || (request.getCharacterEncoding() == null)) {??????????? String encoding = selectEncoding(request);??????????? if (encoding != null){????????????? request.setCharacterEncoding(encoding);??????????? }else{????????????? request.setCharacterEncoding( "UTF-8" );??????????? }??????? }??????? /*??????? if ( encoding != null ) {??????????????????? request.setCharacterEncoding( encoding ) ;??????????????? } else {??????????????????? request.setCharacterEncoding( "UTF-8" ) ;??????????????? }??????? */??????? chain.doFilter(request, response);

??? }

??? public void init(FilterConfig filterConfig) throws ServletException {

??? this.filterConfig = filterConfig;??????? this.encoding = filterConfig.getInitParameter("encoding");??????? String value = filterConfig.getInitParameter("ignore");??????? if (value == null)??????????? this.ignore = true;??????? else if (value.equalsIgnoreCase("true"))??????????? this.ignore = true;??????? else if (value.equalsIgnoreCase("yes"))??????????? this.ignore = true;??????? else??????????? this.ignore = false;