普通的java类获得从jsp页面
在web工程中,jsp页面上的请求时要进行字符编码转换的 通常在web。xml中添加过滤器作用是把request对象中的头信息参数等等进行编码转换 然后继续后续过滤链。
web。xml加入 (尽可能考前排放 过滤器是有顺序的)
Set Character Encoding
lter。 SetCharacterEncodingFilter
encoding
GB18030
ignore
true
Set Character Encoding
/*
下面要创建这个过滤器 上面配置中有个指定路径下的“ lter。 SetCharacterEncodingFilter”当然你要换成你的包路径
...全部
在web工程中,jsp页面上的请求时要进行字符编码转换的 通常在web。xml中添加过滤器作用是把request对象中的头信息参数等等进行编码转换 然后继续后续过滤链。
web。xml加入 (尽可能考前排放 过滤器是有顺序的)
Set Character Encoding
lter。
SetCharacterEncodingFilter
encoding
GB18030
ignore
true
Set Character Encoding
/*
下面要创建这个过滤器 上面配置中有个指定路径下的“ lter。
SetCharacterEncodingFilter”当然你要换成你的包路径
//SetCharacterEncodingFilter过滤器java代码:
package lter;
import rvlet。
Filter;
import 。IOException;
import rvlet。*;
/**
* @author longyue
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SetCharacterEncodingFilter 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;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service。
*/
public void destroy() {
this。encoding = null;
lterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || ( tCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null) {
tCharacterEncoding(encoding);
}
}
// Pass control on to the next filter
Filter(request, response);
}
/**
* Place this filter into service。
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
lterConfig = filterConfig;
this。
encoding = tInitParameter("encoding");
String value = tInitParameter("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
protected String selectEncoding(ServletRequest request) {
return (this。
encoding);
}
}。收起