我已经配置了过滤器在其中使用request.setCharacterEncoding("gbk");并且所有页面都使用gbk编码,但表单提交后还是会乱码.除非使用getBytes("ISO-8859-1")这样才可以,不过好麻烦啊;怎么配置才能不这样啊
解决方案 »
- jsp发布后的问题,帮帮忙看一下。
- 开发视频网站 求好的视频插件
- jsp 空指针的问题?????
- Tomcat后台总是间断性出错而挂掉,急切寻求解答
- 关于引用URL的使用访问 求助(100分)
- 目前TOMCAT下用WEBWORK+SPRING,遇到严重: Error listenerStart,请大家指教
- 哪位jfreechart+jsf高手能指点:jfreechart图表从数据库取数据时页面无法显示问题
- 为什么大家处理clob、blob这样而不是这样呢?
- <img>标签显示上传图片问题
- 希望div改变大小时,引入的图片相应改变长宽大小,怎么做?
- 关于server \web server\servlet
- 急,请大家指点一下,我是新手。
// ----------------------------------------------------- Instance Variables
/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;
/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() { this.encoding = null;
this.filterConfig = null; }
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException { // Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
} // Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
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; }
// ------------------------------------------------------ Protected Methods
/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p>
* The default implementation unconditionally returns the value configured
* by the <strong>encoding</strong> initialization parameter for this
* filter.
*
* @param request The servlet request we are processing
* @return String
*/
protected String selectEncoding(ServletRequest request) { return (this.encoding); }
}
web.xml<filter>
<filter-name>Encoding</filter-name>
<filter-class>framework.filter.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
web.xml<filter>
<filter-name>Two</filter-name>
<filter-class>com.xndag.filter.Two</filter-class>
</filter>
<filter-mapping>
<filter-name>Two</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在com.xndag.filter.Two中直接用了
request.setCharacterEncoding("gbk");
如何正确的格式化???
就是说客户端socket的方法getInputStream()会得到一个InputStream
一般要格式化为字符串
如果网页中提交的参数有中文的,那么就会乱码
这样的话就不太好处理
用UTF-8格式化也没用