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>



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

jsp中国文字形式提交,request对象获取乱码的更多相关文章

  1. 通过request对象获取客户端的相关信息

    通过request对象获取客户端的相关信息 制作人:全心全意 通过request对象可以获取客户端的相关信息.例如HTTP报头信息.客户信息提交方式.客户端主机IP地址.端口号等等. request获 ...

  2. JSP userBean setProperty直接从request中获取参数

    JSP userBean setProperty直接从request中获取参数: form表单Jsp: <%@ page language="java" import=&qu ...

  3. flask中request对象获取参数的方法

    从当前request获取内容: method: 起始行,元数据 host: 起始行,元数据 path: 起始行,元数据 environ: 其中的 SERVER_PROTOCOL 是起始行,元数据 he ...

  4. 不能解决,复选框在request对象获取的信息后显示在用户信息里面为中文的选项名

    因为方框里面value 不用中文?.? 假如用中文呢?  完全可以!!已经试验 如果不用中文,那么中文可以用对象的参数来获得,即在login.jsp中就要用javabean类属性

  5. 常用Request对象获取请求信息

    Request.ServerVariables(“REMOTE_ADDR”) ‘获取访问IPRequest.ServerVariables(“LOCAL_ADDR”) ‘同上Request.Serve ...

  6. 通过Request对象获取请求的IP地址

    /** * 标识要从哪些消息头中获取IP地址 */ private static final String[] getIpArray = {"HTTP_X_FORWARDED_FOR&quo ...

  7. java后端通过request对象获取请求的ip地址工具类

    package cn.zgjkw.battalion.util; import org.apache.log4j.Logger; import javax.servlet.http.HttpServl ...

  8. 通过flask的request对象获取url

    测试了一下:通过发送 GET 到 http://127.0.0.1:5000/test/a?x=1, 后台输出为(官网说明): 1 request.path: /test/a 2 request.ho ...

  9. 通过过滤器和增强request对象解决get提交请求服务器端乱码。

    1.表单用get方式提交 <%@ page language="java" contentType="text/html; charset=UTF-8" ...

随机推荐

  1. css选择器.md

    css选择器总结 1.元素选择器 如:*{},body{},p{} ; xml中note{},to{},from{} 2.class与id选择器 如:.class{},#id{} 3.伪类选择器 选择 ...

  2. LA 3026 - Period KMP

    看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  3. spark提交应用的方法(spark-submit)

    参考自:https://spark.apache.org/docs/latest/submitting-applications.html 常见的语法: ./bin/spark-submit \    ...

  4. get_slave_status.py

    #!/usr/bin/env python#-*- encoding: utf8 -*- import mysql.connectorimport get_mysql_conn_info    &qu ...

  5. ng build --base-href的设定问题

    项目构建部署中遇到的问题: 1.不使用hash,如何解决刷新页面404的问题? 说明: root  指定项目地址路径,默认为nginx下的html index  默认访问index文件 try_fil ...

  6. PL/SQL精明的调用栈分析

    PL/SQL精明的调用栈分析 原文:http://www.oracle.com/technetwork/issue-archive/2014/14-jan/o14plsql-2045346.html ...

  7. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【PHP】php 递归、效率和分析(转)

    递归的定义 递归(http:/en.wikipedia.org/wiki/Recursive)是一种函数调用自身(直接或间接)的一种机制,这种强大的思想可以把某些复杂的概念变得极为简单.在计算机科学之 ...

  9. mysql去除字段内容的空格和换行回车

    MySQL 去除字段中的换行和回车符 解决方法:          UPDATE tablename SET field = REPLACE(REPLACE(field, CHAR(10), ''), ...

  10. [Vue] Dynamic Vue.js Components with the component element

    You can dynamically switch between components in a template by using the reserved <component>  ...