ajax helloworld jsp ajax入门,后台使用jsp
2012-11-26 17:12
155 查看
简单ajax入门。开发环境选择MyEclipse, 服务器tomcat, jsp处理后台任务。
搭建步骤:
在MyEclipse中新建project,例如MyAjax
在WebRoot下添加hello.jsp
修改index.jsp 以及 hello.jsp 如下
index.jsp
hello.jsp
完成两个文件的修改后运行项目即可用ajax实现客户端与服务器的简单交互
搭建步骤:
在MyEclipse中新建project,例如MyAjax
在WebRoot下添加hello.jsp
修改index.jsp 以及 hello.jsp 如下
index.jsp
<html> <head> <title>Hello Ajax version 1</title> <style type='text/css'> * { font-family: Tahoma, Arial, sans-serif; } #helloTitle { color: #48f; font-size: 1.5em; } </style> <script type='text/javascript'> window.onload = function() { document.getElementById('helloBtn').onclick = function() { var xhr; var name = document.getElementById("helloTxt").value; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("GET", "hello.jsp?name=" + name, true); xhr.onreadystatechange = function() { var ready = xhr.readyState; if (ready == 4) { var status = xhr.status; if (status >= 200 && status < 300) { alert(xhr.responseText); } } } // end onreadstatechange xhr.send(); }; // end onclick } </script> </head> <body> <h1 id='helloTitle'>Hello, stranger</h1> <p>Please introduce yourself by entering your name in the box below</p> <input type='text' size='24' id='helloTxt'></input> <button id='helloBtn'>Submit</button> </body> </html>
hello.jsp
<%-- simple JSP to generate some questions - and answers--%> <jsp:directive.page contentType="text/plain"/> <% String name=request.getParameter("name"); System.out.print(name); %> Hello, <%=name%>
完成两个文件的修改后运行项目即可用ajax实现客户端与服务器的简单交互
相关文章推荐
- Windows mobile 开发入门—第一个程序"hello world",链接调试,模拟器的使用
- Drools入门-----------环境搭建,分析Helloworld Drools5.0的xls文件转drl文件提升解析效率 使用BRMS的Tomcat6.0配置
- 在jsp的c标签循环后台对象属性的情况下,使用js提取其中一个id属性使用ajax传到后台删除
- 创建“Hello, world”应用(使用 C#/VB 和 XAML 的 Metro 风格应用)摘自官网(存档)入门必须
- Drools入门-----------环境搭建,分析Helloworld Drools5.0的xls文件转drl文件提升解析效率 使用BRMS的Tomcat6.0配置
- python爬虫"Hello World"级入门实例(二),使用json从中国天气网抓取数据
- 在jsp的c标签循环后台对象属性的情况下,使用js提取其中一个id属性使用ajax传到后台删除
- jsp 通过ajax从后台取值存到前台缓存中,并使用
- iText使用入门,生成HelloWorld.PDF详解
- 微软ASP.Net Ajax:使用AJAX直接调用后台页面类方法
- 使用Ajax模仿Google suggest的搜索提示(Java+JSP+JS实现)
- 添加内核模块之入门helloworld.ko
- 当使用ajax 由前台像后台post 数组类型数据的一些问题(基于springboot)
- jsp页面中使用javascript获取后台放在request或session中的值
- jsp,ajax,json,servlet前后台传值中文乱码解决方法
- Android入门—— Hello, world 解析
- react 使用 fetch 向spring mvc后台发起ajax 请求 options 403
- 使用nwjs开发桌面应用之Hello,World!
- JSP入门初级教程之Session的使用
- 后台使用Spring MVC 4.15 版本 通过 ajaxFileUpload plugin插件上传文件相应时引起的一个小问题,Chrome、Firefox中出现SyntaxError:unexpected token <