首页 文章 精选 留言 我的

精选列表

搜索[前端构建],共10000篇文章
优秀的个人博客,低调大师

前端jsp与后端servlet传值(java web)

jsp中js使用jQuery封装好的 $.ajax()方法与服务器进行交互 var jsonStick = this.strtoJson(); $.ajax({ type : 'post',//不起作用 要用jsonP url : 'controllerServlet',//要传输数据对象的地址 contentType : "application/x-www-form-urlencoded",//转化为form表单传值 data : { "js" : jsonStick }, //前面的js是服务端获取的ID 后面的jsonStick是处理后的json对象 cache : false, dataType : 'text',//这个关系到你能不能正确接收到servlet 响应的数据 async : false, //因为ajax默认是异步调用的,所以得到的返回值是空值,要得到值必须改成同步:async: false success : function(data) { //console.log(data); flag = data; //采用全局变量flag接收数据(data未作处理) }, error : function(msg) { //ajax请求失败后触发的方法 //弹出错误信息 console.log(msg); } }); //数据处理函数 function() { //'':this.note.name, var arr = []; var json = {}; json.note_id = this.id json.note = this.text; json.left = this.left; json.top = this.top; json.zindex = this.zIndex; if (this.sqlId == null) { this.sqlId = 0; } json.sqlId = this.sqlId; arr.push(json); var jsonStick = JSON.stringify(arr);//格式化json数据 return jsonStick; } servlet接收 处理 响应 protected void doGet(.........){ String js = request.getParameter("js");//接收jsp传过来的数据 JSONArray json = JSONArray.fromObject(js);//对数据进行数组转化 JSONObject jsonOne = json.getJSONObject(0);//获取确定的json对象 boolean flag = true; PrintWriter out = response.getWriter(); out.print(flag);//将flag传给jsp out.close(); } jsp接收响应 并对数据进行处理 $.ajax({ type : 'post', url : 'sendServlet', cache : false, dataType : 'json', async : false, //因为ajax默认是异步调用的,所以得到的返回值是空值,要得到值必须改成同步:async: false success : function(data) { //console.log(data.result.note) for (var i in data) { console.log(data[i]) note = new Note(); note.id = data[i].note_id; note.text = data[i].note; note.timestamp = new Date().getTime(); note.left = data[i].left; note.top = data[i].top; note.zIndex = data[i].zindex; } }, error : function(msg) { //ajax请求失败后触发的方法 //弹出错误信息 console.log(msg); } }); 中间用到的jar包以及js https://pan.baidu.com/s/1XEOkM1as_10I92WAzooBuA 密码:gix8

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册