商洛信息港
生活
当前位置:首页 > 生活

StrutsHibernate中解决汉字

发布时间:2019-04-10 20:38:56 编辑:笔名

1.修改l文件,在<web-app>标签后增加如下内容.

<filter>

<filter-name>Set Character Encoding</filter-name>

<filter-class>tEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>gb2312</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>Set Character Encoding</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<servlet>

2.创建类文件(va)

package il;

import Exception;

import lter;

import lterChain;

import lterConfig;

import rvletException;

import rvletRequest;

import rvletResponse;

import availableException;

/**

* Set All HttpRequest Encoding

*/

public class SetEncodingFilter

implements Filter {

/**

* 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;

/**

* Take this filter out of service.

*/

public void destroy() {

coding = null;

lterConfig = 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 result 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 {

if (ignore || (tCharacterEncoding() == null)) {

tCharacterEncoding(selectEncoding(request));

}

Filter(request, response);

}

/**

* Place this filter into service.

* @param filterConfig The filter configuration object

*/

public void init(FilterConfig filterConfig) throws ServletException {

lterConfig = filterConfig;

coding = tInitParameter("encoding");

String value = tInitParameter("ignore");

if (value == null)

nore = true;

else if (ualsIgnoreCase("true") || ualsIgnoreCase("yes"))

nore = true;

else

nore = false;

}

/**

* 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

*/

protected String selectEncoding(ServletRequest request) {

return (coding);

}

/**

* Returns the filterConfig.

* @return FilterConfig

*/

public FilterConfig getFilterConfig() {

return filterConfig;

}

/**

* Sets the filterConfig.

* @param filterConfig The filterConfig to set

*/

public void setFilterConfig(FilterConfig filterConfig) {

lterConfig = filterConfig;

}

}