ajax代码

var obtn=document.getElementsByTagName('input')[0];
obtn.onclick=function () {
var xhr=null;
try{
xhr=new XMLHttpRequest();
}catch(e){
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}

//第一种方法用get get 中由于要编码可以用encodeURI('刘伟')但是不知道为什么出来是问号就在后台想把编码转好了,然后还要注意get中由于会出现缓存的问题,可以随时加个随机数,就是new Date()当时间当做随机数
/*xhr.open('get','send.jsp?name='+'刘伟'+'&date=30&'+new Date().getTime(),true);
xhr.send();*/

//第二种方法是post方法,没有缓存也不用编码
xhr.open('post','send.jsp',true);
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
xhr.send('name=刘伟&date=30');
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
alert(xhr.responseText);
}}}}

jsp后台

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<html><body>
<%

String name=request.getParameter("name");
String date=request.getParameter("date");
//转换成一个字节数组,利用iso-8859-1编码  注意这里!因为编码后才能够解决前台输出中文乱码的额问题。
name = new String(na.getBytes("iso-8859-1"),"UTF-8"); //把name转为utf-8编码
out.println("姓名"+name);
out.println("时间"+date);
%>
</body></html>

最新文章

  1. [转]retina屏下支持0.5px边框的情况
  2. 托马斯微积分答案.djvu的书签
  3. UIAlertView&#39; is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlert
  4. 烂泥:使用snmpwalk采集设备的OID信息
  5. [CareerCup] 1.7 Set Matrix Zeroes 矩阵赋零
  6. Sublime ctags 函数跳转插件安装
  7. ecshop网站建设手机版wap版出现lib.debug.php on line 303
  8. php中的数组遍历的几种方式
  9. Java数据库连接池比较(c3p0,dbcp,proxool和BoneCP)
  10. 快速搭建属于自己的数据库——mongodb
  11. 基于vue-cli构建vue-router的入门级demo
  12. 利用python执行shell脚本 并动态传参 及subprocess基本使用
  13. spring boot 2 统一异常处理
  14. [20190401]关于semtimedop函数调用.txt
  15. bzoj3514(主席树+lct)
  16. typedef定义数组类型
  17. MVC5控制器传值的三种方式(ViewData,ViewBag,TempData),刚刚学习MVC5的新手,希望各位大神多多指教
  18. ELK 性能(3) — 在 Docker 上运行高性能容错的 Elasticsearch 集群
  19. redis主从配置(docker实现)
  20. 【Android】使用Pull生成/解析XML文件

热门文章

  1. Network of Schools --POJ1236 Tarjan
  2. javascirpt对象运用与JS变量
  3. javascript作用域链与原型链有联系吗?
  4. css 水平垂直居中总结
  5. Eclipse不显示项目栏
  6. [OC] Podfile 格式内容
  7. Gradle版本变更的问题
  8. Asp.NET Visible属性与HTML display:none
  9. Angular 2.0 的设计方法和原则
  10. qt开源社区学习