zoukankan      html  css  js  c++  java
  • jsp中国文字形式提交,request对象获取乱码


    jsp表单提交中文字符,request对象获取时乱码解决方法

    第一种:
    在request对象获取页面Charset中的“C”大写,且页面无中文字符,最好用英文,否则MyEclipse无法保存此页面编码(表单页面能够不大写“C”)
    <%@ page contentType="text/html;Charset=GB2312" %>


    另外一种:

    tomcat4.x支持中文传码。但5.x不支持。假设用5.0以上的版本号就得转码了。
    就是这样的格式

    <%@ page contentType="text/html;charset=GB2312" %>

    String strKeyWords=new String(request.getParameter("key_words").getBytes("iso8859_1"),"gb2312");

     这个是我们的项目解决sqlserver中文乱码的方案。能够试试看

    --------------------------------------------------------------------------

    第三种:
     在  jsp、servlet中 申明这种方法转换一下: (表单JSP页面的编码一定要GB2312,且 charset中的“c”小写。此方法JSP页面就能够写中文字符
      即:<%@ page contentType="text/html;charset=GB2312" %>)
      <%!public String handleString(String str){
    		try{
    			byte bb[]=str.getBytes("ISO-8859-1");
    			str=new String(bb);
    		}catch(Exception e){
    			System.out.println("字符转换失败"+e);
    		}
    		return str;
    	} %>
    
        <%
         String logname=request.getParameter("參数ID");
         logname=handleString(logname);
        %>
    


    
    
    
    第四种:
    在request对象获取提交的页面开头写(注意:此方法表单提交方式仅仅能是post,并且表单页码的编码方式和request.setCharacterEncoding("utf-8"); 必须保持一致)

    <%@ page contentType="text/html; charset=utf-8"%> 
    <% request.setCharacterEncoding("utf-8"); %> 

    第一行是页面编码方式
    第二行是传值编码方式

    表单页面
    <%@ page contentType="text/html; charset=utf-8"%>
    <html> 
    <body> 
    <form method="post" action="2.jsp"> 
    <div align="center"> 
    <input type="text" name="name"> 
    <input type="submit" name="Submit" value="Submit"> 
    </div> 
    </form> 
    </body> 
    </html> </span>

    request对象获取页面
    <%@ page contentType="text/html; charset=utf-8"%> 
    <% request.setCharacterEncoding("utf-8"); %> 
    <html> 
    <body> 
    <%=request.getParameter("name")%> 
    </body> 
    </html></span>




    
    

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    linq
    存储过程动态显示top条数
    js正则表达式
    WebClient异步下载文件
    C++ socket编程基础(ZT)
    Oracle数据导入导出imp/exp命令 10g以上expdp/impdp命令(转载)
    C#获取各种格式的系统时间
    C++中对sprintf()函数的说明(转)
    史上最全前端面试题(含答案)B篇
    常用正则表达式
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4871792.html
Copyright © 2011-2022 走看看