前面提到过我的一个低级失误并对servlet的setCharacterEncoding有了正确认识。
主要是基于这么一个思路解决我的问题:
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
...
<form method="post" action="/servlet" accept-charset="utf-8">
<input type="hidden" name="_charset_"/>
<input type="text" name="text"/>
<input type="submit" value="Submit"/>
</form>
这个表单配合原来在weblogic下写的filter代码,在IE和firefox下运行正常。但既然遵循servlet规范,不能在filter中通过_charset_这个request参数来获取浏览器对post body的真实编码,只能想点歪门邪道了。向jsessionid取经,这个表单改成这样:(关于URL中的分号,请参考RFC1738,这里有个中文版)
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
...
<form method="post" action="/servlet;_charset_=utf-8" accept-charset="utf-8">
<input type="hidden" name="_charset_"/>
<input type="text" name="text"/>
<input type="submit" value="Submit"/>
</form>
filter的改造就略了,无非是hack下request uri。幸好遗留应用并不需要url中重写jsessionid。wink
测试,运行,firefox正常了,IE又不正常。哦,恍然大雾啊,原来firefox是严格的根据accept-charset来编码,若accept- charset不存在,则按response或者meta http-equiv="Content-Type"中的声明来编码,最后把编码方式放到_charset_隐藏域。而IE还是顽固的只按照 response或者meta http-equiv="Content-Type"中的声明来编码,并把编码方式放到_charset_隐藏域。原来IE无视accept- charset的存在。我原先一直以为_charset_隐藏域只是IE对accept-charset的一个强制辅助呢,又一个一知半解的典型...
得了,只能让firefox和IE同流合污了。最终,表单变成这样:
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
...
<form method="post" action="/servlet;_charset_=gbk">
<input type="text" name="text"/>
<input type="submit" value="Submit"/>
</form>
在IE和firefox下均测试通过。
http://sorphi.iteye.com/blog/177716
分享到:
相关推荐
调用pb开发的webserver(HTTP POST) .../*获取结果 HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <short xmlns="http://webi.org">short*/ //出参是json格式{"statusCode":"2"}
在后端 允许跨域的情况下,axios post 将数据传到后端,但是后端无法接收,始终为空 请求能正常到达后端,那么肯定传数据的地方的问题了 所以这里headers设置为 headers:{"Content-Type":'application/x-...
type:"post", dataType:"json", //data:{reviewer:encodeURI(reviewer)}, contentType: "application/x-www-form-urlencoded; charset=GBK", // headers:{"ClientCallMode" : "ajax"},//添加请求头部 enctype=...
实例:form表单触发POST请求 <html> <head> <meta charset="utf-8"> <title>POST请求</title> </head> <body> <form action="post.php" method="post"> 名字: <input type="text" name="fname"> 年龄: ...
meta charset="UTF-8"> <title>Document</title> </head> <body> <form id="form"> <input type="text" name="username"> <input type="file" name="file"> <...
查了很多资料都说,get方法的参数是有限制的,post方法的参数的长度是无限制,这也是post相比get的优势一直。 在ajax中使用post方法,用常规的参数格式:param1=a1¶m2=a2 ,当参数长度过长时,依然提交不成功。...
实验一:HTTP协议POST 实验目的 通过ajax实例深入理解http协议之post方法。 二、实验用到的工具软件 ...<form action="a2.php" name="form1" method="post"> 姓名: 年龄: <input type="submit" value="
那么本篇文章主要就给大家详细介绍其中的get方法即PHP通过get变量获取form表单数据的具体方法以及用处,后期文章中再继续给大家介绍post的具体用法作用。 下面给大家带来具体的代码示例: 1、form表单代码示例(表单...
语言:English 用于编辑对Web服务器的...支持编辑表单accept-charset。 版本1.3 1.支持保存提交历史记录。 版本1.3.3 1.更新到清单V2。 您可以在这里找到源代码:https://github.com/zsxwing/Form-Editor欢迎任何贡献。
需求:请求第三方后台接口返回一段html字符串如下,由前端去实现form表单的POST提交, 说明:form表单submit()实现自动提交input标签hidden,注意script代码中的document.redirect.submit(); <html> <...
后台接收到的数据一直显示null 原因: 使用@RequestBody标签接收json...charset=utf-8。 后台接收请求的方法的参数可以用String类型 @RequestBody 是作用在形参列表上,用于将前台发送过来固定格式的数据【xml 格式或
form action="http://blog.csdn.net/gnail_oug" method="post"> <!--input获得焦点后按回车form自动提交--> <input type="text"> </form> </body> </html> 有多个input时(不管是否...
public static String REQUEST_METHOD_POST = "POST"; public static String REQUEST_METHOD_GET = "GET"; // 媒体类型 public static String MIME_TYPE_FORM = "application/x-www-form-urlencoded;charset=...
一. django form表单验证引入 有时时候我们需要使用get,post,put等方式在前台HTML页面提交...form action="url" method="post" enctype="multipart/form-data">{% csrf_token %} <input type="text" name="us
public void postForm() { // 创建默认的httpClient实例. CloseableHttpClient httpclient = HttpClients.createDefault(); // 创建httppost HttpPost httppost = new HttpPost(...
FORM METHOD=POST ACTION=""> <input type="password" id="input1"> <input type="password" id="input2"> <input type="button" value="test" </FORM> [removed] function check() { with...
本文主要介绍如何使用Angularjs $http服务以POST方法向服务器传递json对象数据。 具体如下: 一、$http POST方法默认提交数据的类型为application/json var data = {'wid':'0', 'praise' :...charset=utf-8 {'wid':'0
在用jquery处理html5的应用的时候,一直在...解决方法: 代码如下:$.ajaxSetup({ contentType: “application/x-www-form-urlencoded; charset=utf-8”});$.post(“test.php”, { name: “i5a6”, time: “2pm” },
<!... <meta charset="UTF-8"> ... <form action="fileUploadController" method="post" enctype="multipart/form-data"> 上传文件:<input type="file" name="filename"/> </form> </html>
用POST发送数据,在2号线函数(也是ajax发送数据的函数:ajaxCall)必须加上一句:xmlObject.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded”); 接着使用xmlObject.send(data);发送 2.3...