我的mysql myeclipse都能显示中文,但是页面出来就是问号。我想加一个过滤器,求具体怎么做,最好有图。 100
2个回答
展开全部
这是我的过滤器的代码以及在web.XML中的配置:
package filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.omg.CORBA.Request;
public class EncodeFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
System.out.println("字符编码过滤器");
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig config) throws ServletException {
// TODO Auto-generated method stub
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>web</display-name>
<filter>
<filter-name>encode</filter-name>
<filter-class>filter.EncodeFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encode</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>calculate.html</welcome-file>
<welcome-file>audiodg.html</welcome-file>
<welcome-file>one.jsp</welcome-file>
</welcome-file-list>
</web-app>
2015-05-24
展开全部
也可以把设置myEclipse中默认的contentTyepe。
步骤是:windows->preferences->Generl->ContentType.然后设置成UTF-8.一定要update~~
在JSP页面头部加入下面这句话,告诉浏览器应该调用UTF-8的字符集。
步骤是:windows->preferences->Generl->ContentType.然后设置成UTF-8.一定要update~~
在JSP页面头部加入下面这句话,告诉浏览器应该调用UTF-8的字符集。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询