`
xvm03
  • 浏览: 140715 次
  • 来自: ...
社区版块
存档分类
最新评论

servlet,yui简单无刷新提交

阅读更多

JAVA代码:

TestServlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  String name=(String)request.getParameter("name");
  System.out.println("name:"+name);
  request.setAttribute("name", "ming");
   PrintWriter out =response.getWriter();
   response.setContentType("text/xml");  
    response.setHeader("Cache-Control", "no-cache");  
    String ids="hello,China!";  
    //将ids返回给客户端  
    out.write("ids:"+ids);
    out.write("name:"+name);
    out.flush();
   
 }

web.xml配置:

<servlet>
  <servlet-name>TestServlet</servlet-name>
  <servlet-class>test.TestServlet</servlet-class>

 </servlet>
 <servlet-mapping>
  <servlet-name>TestServlet</servlet-name>
  <url-pattern>/TestServlet</url-pattern>
 </servlet-mapping>

 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

 

 

前台页面:index.jsp

 

 <body>
  <form action="#"  method="post">
  name:<input id="name" type="text" name="name"><br>
  <input type="button"  value="asdf" onclick="makeRequest()">
  <div id="divID">
  </div>
  </form>
  </body>
  <script src="js/yahoo.js"></script>  
 <script src="js/event.js"></script>  
 <script src="js/connection.js"></script> 
 
  <script type="text/javascript">
 var div = document.getElementById('divID');

var handleSuccess = function(o){
 if(o.responseText !== undefined){
  div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
  div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
  div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
  div.innerHTML += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>";
  div.innerHTML += "<li>Server response: " + o.responseText + "</li>";
  div.innerHTML += "<li>Argument object: Object ( [foo] => " + o.argument.foo +
       " [bar] => " + o.argument.bar +" )</li>";
 }
}

var handleFailure = function(o){
 if(o.responseText !== undefined){
  div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
  div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
  div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
 }
}

var callback =
{
  success:handleSuccess,
  failure: handleFailure,
  argument: { foo:"foo", bar:"bar" }
};

function makeRequest(){
  var sUrl = "TestServlet?name="+document.getElementById("name").value;
 var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
}
  </script>

分享到:
评论

相关推荐

    YUI js方法使用列子

    YUI 是 jquery 一样网页使用的javascrpit 方法库。

    YUI 入门教程YUI 入门教程YUI 入门教程

    YUI教程YUI 入门教程YUI 入门教程YUI 入门教程

    yuicompressor-yui compressor

    yuicompressor-2.4.2.jar yuicompressor-2.4.7.jar jsZip.exe yuicompressor yui compressor js压缩工具 javascript压缩工具 css压缩工具 ------------------------------------ //压缩JS java -jar yui...

    yui_2.9.0前端UI

    YUI 库,全称Yahoo! UI Library。是一组工具和控件,用JavaScript写成, 为的是用DOM 脚本,DHTML和AJAX等技术创建丰富的网页交互式应用程序。 YUI 基于BSD协议,对所有的使用方式都是免费的。YUI 项目包括YUI 库和两...

    yui3-master.zip

    yui3-master.zip

    雅虎 用户接口库YUI

    连接管理(Connection Manager ):这个工具包帮助你管理XMLHttpRequest(一般被称为AJAX)事务,它提供对表单提交(form posts),错 误捕获(error handling)和callbacks的全面支持。该工具包也支持文件的上传...

    yuitest YUI测试工具

    YUI Test is a complete testing framework for JavaScript and Web applications. You can use the simple JavaScript syntax to write unit tests that can be run in web browsers or on the command line, as ...

    yui_2.6.0r2

    yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2

    js 压缩YUI

    雅虎的东西,简单的操作很好用 使用例子:java -jar D:\yuicompressor\yuicompressor\yuicompressor.jar E:\js\all.js -o E:\wap\wap2\js\all-min.js --charset utf-8 当然要装jdk了 不然就玩完了

    yui 资源包

    yui 源码下载,3.9.0 r2 包,最新版本

    yuicompressor,给YUI Compressor添加右键命令

    YUI Compressor非常好用,特别是JS的混淆是众多JS Coding的最爱。可惜官网提供的版本都不具备右键功能,每次压缩都要cmd输入一些命令实在是繁琐,本文就介绍如何给YUI Compressor添加右键命令,方便使用。 网上已有...

    从YUI2到YUI3看前端的演变 pdf

    YUI3 引入了粒度更细的模块管理方式,通过异步 HTTP 请求加载模块、然后执行...YUI是个“学院派”的框架,以性能和严谨著称,易用性相对而言弱了一些。它能否在已经拉开的 JavaScript 框架大战中胜出,让我们拭目以待。

    YUI中文文档CHM

    YAHOO YUI 中文文档 AJAX 详细 比较好用

    从YUI2到YUI3看前端的演变

    从YUI2到YUI3看前端的演变

    yui压缩

    yui压缩

    YUI3 dialog组件

    基于YUI3的dialog组件该组件是基于YUI3开发的,功能强大,详细见http://www.qiqicartoon.com

    yahoo yui 实例教程

    利用Yahoo YUI库做的一个TREE实例,很详细的阐述了YUI的使用原理

    yui.rar 例子

    yui的例子,左中右3个模块 ,非常简单的例子

    YUI3 完整包

    Yahoo! UI Library (YUI) 是一个开放源代码的 JavaScript 函数库,为了能建立一个高互动的网页,它采用了AJAX, DHTML 和 DOM 等程式码技术。它也包含了许多 CSS 资源。

    yuicompressor-2.4.8.jar

    yuicompressor.jar是JS压缩工具、前端优化神器、yuicompressor-2.4.8.jar

Global site tag (gtag.js) - Google Analytics