我有两个过滤器!
一个是 /* 过滤所有,作用是字符编码过滤,编码格式参数为gb2312
一个dwr的 /dwr/*
我的第一个字符编码过滤器过滤了所有,结果把/dwr/*也过滤了,导致 dwr 不能用了,怎么样才能使,第一个字符编码过滤器在过滤的时候不过滤url为 /dwr/*的请求
···
谢谢了如果能通过其他方法解决也可以,反正能把问题解决就行!
一个是 /* 过滤所有,作用是字符编码过滤,编码格式参数为gb2312
一个dwr的 /dwr/*
我的第一个字符编码过滤器过滤了所有,结果把/dwr/*也过滤了,导致 dwr 不能用了,怎么样才能使,第一个字符编码过滤器在过滤的时候不过滤url为 /dwr/*的请求
···
谢谢了如果能通过其他方法解决也可以,反正能把问题解决就行!
解决方案 »
- jsp中的动态效果实现,,求解。。。。
- struts2 返回json问题
- js的return问题
- jsp下载文件
- 急问!!!!!!::::如何释放Tomcat配置的DBCP连接池.
- 通过JAVA还能把word、powerpoint文件转成WEB形式的网页文件??
- oracle 在 red hat 9 上不能连接的问题!!!!
- 急!急!急!jsf 动态表单。
- 连接数据库的问题
- 关于json存值报错 Servlet.service() for servlet [default] in context with path [/examin
- 可不可以这样做?
- Jquery tools 工具怎么取得文本框的值
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping> <filter>
filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>legou.log.CharFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
就这里两个配置!字符串编码过滤器如下:protected String encoding = null;
protected FilterConfig filterConfig = null;
public void destroy() {
this.encoding = null;
this.filterConfig = null;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
response.setCharacterEncoding("text/html;charset="+encoding+"");
request.setCharacterEncoding(encoding);
chain.doFilter(request, response); }
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
} 我也不知道撒原因了,反正不行,项目中有hibernate···
response.setCharacterEncoding("text/html;charset="+encoding+"");
那位帮我研究一下应该怎么改呀 ?
response.setCharacterEncoding(encoding);
我改成这样dwr 能用了
但是编码没转换过来
protected FilterConfig filterConfig = null;
public void destroy() {
this.encoding = null;
this.filterConfig = null;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
response.setCharacterEncoding("text/html;charset="+encoding+"");
request.setCharacterEncoding(encoding);
//这儿添加代码
String str=request.getServletPath();
if(str.indexOf("dwr")==1)
{
chain.doFilter(request, response); }
chain.doFilter(request, response); }
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}
String str=request.getServletPath();
if(str.indexOf("/dwr/")==1)
{
chain.doFilter(request, response); }
我认为这个方案就简单。过滤器里一样要进行处理,加上这个判断不就行了JAVA面试题,Java代码,Java学习资料,请到:JAVA世纪网
数据库面试题,智力面试题,相声,笑话,请到:老紫竹的家
这样既可以解决问题,又可以解决紧耦合的问题
在大程序上的设计上会有BUG的
response.setCharacterEncoding("text/html;charset="+encoding+"");改成 response.setCharacterEncoding(encoding");就好了··
<filter-name>EncodingCharAtServlet</filter-name>
<filter-class>com.gw.dao.EncodingCharAtServlet</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingCharAtServlet</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>过滤器类中的代码:
public class EncodingCharAtServlet extends HttpServlet implements Filter { String encoding = ""; public void init(FilterConfig arg0) throws ServletException {
String stuEncoding = arg0.getInitParameter("encoding");
if (stuEncoding != null) {
encoding = stuEncoding;
}
} public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
arg0.setCharacterEncoding(encoding);//
arg2.doFilter(arg0, arg1);// 继续过滤
}
}
String str=request.getServletPath();
if(str.indexOf("/dwr/")==1)
{
chain.doFilter(request, response);
}3.不要嘲笑新手,高手都是从菜鸟阶段过来的,我们一直在努力!
<filter-name>EncodingCharAtServlet </filter-name>
<filter-class>com.gw.dao.EncodingCharAtServlet </filter-class>
<init-param>
<param-name>encoding </param-name>
<param-value>UTF-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingCharAtServlet </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping> 过滤器类中的代码:
public class EncodingCharAtServlet extends HttpServlet implements Filter { String encoding = ""; public void init(FilterConfig arg0) throws ServletException {
String stuEncoding = arg0.getInitParameter("encoding");
if (stuEncoding != null) {
encoding = stuEncoding;
}
} public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
arg0.setCharacterEncoding(encoding);//
arg2.doFilter(arg0, arg1);// 继续过滤
}
}