Java jsp sevlet中文乱码问题解决方案

系统 1564 0
<!-- Feedsky FEED发布代码开始 --> 如果您喜欢这些文章,欢迎点击此处订阅本Blog <!-- FEED自动发现标记开始 --> <link title="RSS 2.0" type="application/rss+xml" href="http://feed.feedsky.com/softwave" rel="alternate"> <!-- FEED自动发现标记结束 --> Blog 订阅

<!--Google 468*60横幅广告开始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "image"; //2007-07-26: CSDN google_ad_channel = "6063905817"; google_color_border = "6699CC"; google_color_bg = "E6E6E6"; google_color_link = "FFFFFF"; google_color_text = "333333"; google_color_url = "AECCEB"; google_ui_features = "rc:6"; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--Google 468*60横幅广告结束-->

Java Web开发中的中文乱码问题的处理办法,jsp、javabean、servlet等稍改动后均适用。
-------------------JAVA代码------------------
  1. package tools;

  2. import javax.servlet.http.HttpServlet;
  3. import javax.servlet.Filter;
  4. import javax.servlet.FilterConfig;
  5. import javax.servlet.ServletRequest;
  6. import javax.servlet.ServletResponse;
  7. import javax.servlet.FilterChain;

  8. public class EncodingFilter extends HttpServlet implements Filter
  9. {
  10. private FilterConfigconfig= null ;
  11. private StringtargetEncoding= "GBK" ;

  12. public void init(FilterConfigfilterConfig)
  13. {
  14. this .config=filterConfig;
  15. this .targetEncoding=config.getInitParameter( "encoding" );
  16. }

  17. public void destroy()
  18. {
  19. config= null ;
  20. targetEncoding= null ;
  21. }

  22. public void doFilter(ServletRequestservletRequest,ServletResponseservletResponse,
  23. FilterChainfilterChain)
  24. {
  25. ServletRequestrequest=(ServletRequest)servletRequest;
  26. try
  27. {
  28. request.setCharacterEncoding(targetEncoding);
  29. filterChain.doFilter(servletRequest,servletResponse);
  30. }
  31. catch (Exceptionex)
  32. {
  33. ex.printStackTrace();
  34. }
  35. }

  36. }

------------web.xml------------
  1. < filter >
  2. < filter-name > EncodingFilter </ filter-name >
  3. < filter-class > db.EncodingFilter </ filter-class >
  4. < init-param >
  5. < param-name > encoding </ param-name >
  6. < param-value > GBK </ param-value >
  7. </ init-param >
  8. </ filter >
  9. < filter-mapping >
  10. < filter-name > EncodingFilter </ filter-name >
  11. < url-pattern > /* </ url-pattern >
  12. </ filter-mapping >

在sqlserver2000和mysql中试验通过。
以上为csdn论坛http://topic.csdn.net/u/20081205/13/c00edcf9-cc46-43eb-b2cf-96adb0c99f24.html中http://hi.csdn.net/xiaowu_wings发的帮助帖子,向原作者鸣谢!

<!--新Google 468*60横幅广告开始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; /* 468x60, 创建于 08-8-6 */ google_ad_slot = "7368701459"; google_ad_width = 468; google_ad_height = 60; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--新Google 468*60横幅广告结束-->

<!--新Google 468x15 横链接单元开始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; /* 468x15 横链接单元 */ google_ad_slot = "5785741422"; google_ad_width = 468; google_ad_height = 15; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--新Google 468x15 横链接单元结束-->

<!-- Google Reader shared发布代码开始 --><script type="text/javascript" src="http://www.google.com/reader/ui/publisher.js"></script><script type="text/javascript" src="http://www.google.com/reader/public/javascript/user/00697638153916680411/state/com.google/broadcast?n=5&amp;callback=GRC_p%28%7Bc%3A%22green%22%2Ct%3A%22%5Cu8FD9%5Cu4E9B%5Cu6587%5Cu7AE0%5Cu4E5F%5Cu503C%5Cu5F97%5Cu4E00%5Cu770B%22%2Cs%3A%22false%22%7D%29%3Bnew%20GRC"></script><!-- Google Reader shared发布代码结束 -->

Java jsp sevlet中文乱码问题解决方案


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论