struts处理中文乱码问题总结
生活随笔
收集整理的這篇文章主要介紹了
struts处理中文乱码问题总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
亂碼中有三種情況:
㈠頁面顯示中文亂碼?
㈡傳遞參數中文亂碼?
㈢國際化資源文件亂碼?
詳細摘出:傳遞參數中文亂碼?
傳遞參數出現的亂碼,參數的內容為中文。比如在struts應用中,簡單的一個登錄界面中,需要傳遞的登錄名為中文時,你沒經處理之前,是會出現亂碼傳遞的,為了讓我們能看到顯示的亂碼,我們在對應的Action類的子類里,修改一下,用System.out把接受到的參數輸出,代碼如下:?Java代碼 ?public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, ?HttpServletResponse response) ...{ ?DynaActionForm loginForm = (DynaActionForm) form; ?String username = (String) loginForm.get("username"); ?String password = (String) loginForm.get("password"); ?System.out.println("username:"+username); ?System.out.println("password:"+password); ?if (username.equals("ivorytower") && password.equals("123456")) ...{ ?return mapping.findForward("success"); ?} ?return mapping.findForward("fail"); ?} ?
那么當你提交了中文輸入后就會出現亂碼了。?
具體的解決方法:?
①修改Tomcat---->conf----->server.xml文件,在修改端口的標簽后面加一行代碼,如下:?Xml代碼 ?<Connector port="8080" protocol="HTTP/1.1" ??connectionTimeout="20000" ??redirectPort="8443" ?URIEncoding="UTF-8"/> ?
轉自:http://www.iteye.com/topic/179279
㈠頁面顯示中文亂碼?
㈡傳遞參數中文亂碼?
㈢國際化資源文件亂碼?
詳細摘出:傳遞參數中文亂碼?
傳遞參數出現的亂碼,參數的內容為中文。比如在struts應用中,簡單的一個登錄界面中,需要傳遞的登錄名為中文時,你沒經處理之前,是會出現亂碼傳遞的,為了讓我們能看到顯示的亂碼,我們在對應的Action類的子類里,修改一下,用System.out把接受到的參數輸出,代碼如下:?Java代碼 ?public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, ?HttpServletResponse response) ...{ ?DynaActionForm loginForm = (DynaActionForm) form; ?String username = (String) loginForm.get("username"); ?String password = (String) loginForm.get("password"); ?System.out.println("username:"+username); ?System.out.println("password:"+password); ?if (username.equals("ivorytower") && password.equals("123456")) ...{ ?return mapping.findForward("success"); ?} ?return mapping.findForward("fail"); ?} ?
那么當你提交了中文輸入后就會出現亂碼了。?
具體的解決方法:?
①修改Tomcat---->conf----->server.xml文件,在修改端口的標簽后面加一行代碼,如下:?Xml代碼 ?<Connector port="8080" protocol="HTTP/1.1" ??connectionTimeout="20000" ??redirectPort="8443" ?URIEncoding="UTF-8"/> ?
轉自:http://www.iteye.com/topic/179279
總結
以上是生活随笔為你收集整理的struts处理中文乱码问题总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu下安装配置JDK1.7
- 下一篇: Lua元表(Metatable)简易教程