是JSP吗?
在传输过程中加一个过滤器Filter
把内容转换成UTF就可以了
在传输过程中加一个过滤器Filter
把内容转换成UTF就可以了
解决方案 »
- 公司每周三要安排讲课 谁好的意见吗 急
- java怎么测试一个邮箱地址是否存在且能连通,还有apache commons email发送邮件怎么确定邮件确实投递到了对方邮箱,或者说的确发送成功了
- 请问如何调用ocx控件 js 我在线等
- SQL 时间函数
- 一个常见的 关于 ORM 界面绑定的问题 目前为止,一直还没人解答出来
- 一个XML文件的内容用DAG表来表示了,如何在这个表上进行XML表达式的查询?
- 关于用Middlegen-Hibernate-r5来生成 hibernate的配置文件的问题,我搞了好久了也还没有搞定呀!请高手帮帮我呀!
- struts1.2中的ActionServlet类没有getDebug方法,请问我要怎样才能得到web.xml中的debug配置?谢谢!
- 我虽然能将某个类的所有Field取出来,但我怎样才能创建这个类的对象,并对每个Field进行赋值呢?
- 请运行过petstore的人帮忙,求救。(来者有分)
- 链接数据库的效率问题?
- getHibernateTemplate()有这个功能吗?
filter a->utf-8
// TODO 自动生成方法存根
context = arg0.getServletContext();
encoding = arg0.getInitParameter("encoding");
// System.out.println("init........");
} public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO 自动生成方法存根
try {
if (encoding != null && encoding.length() > 0) {
arg0.setCharacterEncoding(encoding);
// System.out.println("in filter encoding=" + encoding);
context.log("in filter.encoding=" + encoding); } else {
arg0.setCharacterEncoding(DEFAULT_CHARACTER_ENCODING);
}
} catch (UnsupportedEncodingException e) {
// TODO 自动生成 catch 块
arg0.setCharacterEncoding(DEFAULT_CHARACTER_ENCODING);
e.printStackTrace();
}
arg2.doFilter(arg0, arg1);
} // public void destroy() {
// // TODO 自动生成方法存根
//
// }}
要么就在jsp页面用中文编码 像GBK,然后在后后台的源码中设置request为中文编码,再插入库中
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class EncodingFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK");
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse)response;
String url= httpRequest.getRequestURI();
Object object = httpRequest.getSession().getAttribute("userSession");
if(object!=null || url.endsWith("login.jsp") || url.startsWith(httpRequest.getContextPath()+"/LoginServlet")
|| url.startsWith(httpRequest.getContextPath()+"/css")){
chain.doFilter(request, response);
}else{
httpResponse.sendRedirect(httpRequest.getContextPath()+"/login.jsp");
}
} public void init(FilterConfig arg0) throws ServletException { }}web.xml配置如下:
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.s10.rg.util.EncodingFilter</filter-class>
</filter> <filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>