tomcat request时乱码问题
网上说要配置一个过滤器放在web.xml里,请问该如何配置,放在xml里的什么位置,class文件又应该放在哪我照你说的做了,可是,可是把那段东西放在web.xml里的时...
网上说要配置一个过滤器放在web.xml里,请问该如何配置,放在xml里的什么位置,class文件又应该放在哪
我照你说的做了,可是,可是把那段东西放在web.xml里的时候再启动tomcat,连文件也显示不出来了
提示HTTP Status 404 - /JSP/addressshuru.jsp
type Status report
message /JSP/addressshuru.jsp
description The requested resource (/JSP/addressshuru.jsp) is not available.
Apache Tomcat/5.0.30 该怎么办 展开
我照你说的做了,可是,可是把那段东西放在web.xml里的时候再启动tomcat,连文件也显示不出来了
提示HTTP Status 404 - /JSP/addressshuru.jsp
type Status report
message /JSP/addressshuru.jsp
description The requested resource (/JSP/addressshuru.jsp) is not available.
Apache Tomcat/5.0.30 该怎么办 展开
1个回答
展开全部
下面这段代码放在web.xml里,中文地方要改改哦
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>你的包名.CLASS名</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
CLASS文件建立在src文件夹里的随便一个地方```把包名记住就可以了```下面是CLASS文件,记得把包名和类名改对
package filters;
import java.io.IOException;
import javax.servlet.*;
public class SetCharacterEncodingFilter
implements Filter
{
protected String encoding;
protected FilterConfig filterConfig;
protected boolean ignore;
public SetCharacterEncodingFilter()
{
encoding = null;
filterConfig = null;
ignore = true;
}
public void destroy()
{
encoding = null;
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);
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig)
throws ServletException
{
this.filterConfig = filterConfig;
encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if(value == null)
ignore = true;
else
if(value.equalsIgnoreCase("true"))
ignore = true;
else
if(value.equalsIgnoreCase("yes"))
ignore = true;
else
ignore = false;
}
protected String selectEncoding(ServletRequest request)
{
return encoding;
}
}
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>你的包名.CLASS名</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
CLASS文件建立在src文件夹里的随便一个地方```把包名记住就可以了```下面是CLASS文件,记得把包名和类名改对
package filters;
import java.io.IOException;
import javax.servlet.*;
public class SetCharacterEncodingFilter
implements Filter
{
protected String encoding;
protected FilterConfig filterConfig;
protected boolean ignore;
public SetCharacterEncodingFilter()
{
encoding = null;
filterConfig = null;
ignore = true;
}
public void destroy()
{
encoding = null;
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);
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig)
throws ServletException
{
this.filterConfig = filterConfig;
encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if(value == null)
ignore = true;
else
if(value.equalsIgnoreCase("true"))
ignore = true;
else
if(value.equalsIgnoreCase("yes"))
ignore = true;
else
ignore = false;
}
protected String selectEncoding(ServletRequest request)
{
return encoding;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询