服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

源代码解析――初探 ajaxtags


  ajaxtags项目是在现有的struts html标记库的基础上,添加对ajax支持。 ajaxtags改写了struts标签类org.apache.struts.taglib.html.formtag和org.apache.struts.taglib.html.basehandlertag,并使用struts的plugin技术,使得struts提供了对ajax的支持。 以下是jsp中简单的示例:
  
  <html:form action="example1" ajaxref="example1">
  first name: <html:text property="firstname" size="25" value="frank" />
  <br>
  last name: <html:text property="lastname" size="25" value="zammetti" />
  <br>
  <html:button property="button" value="click to do ajax!" ajaxref="button" />
  </html:form>
  result:<br>
  <span id="example1_resultlayer"> </span>
  
  注意ajaxref属性。 ajaxref属性中内容是在ajax-config.xml中定义的,如本示例的配置部分如下:
  
  <!doctype ajaxconfig public "ajaxconfig" "ajaxconfig">
  <ajaxconfig>
  <!-- define a custom request handler that generates xml for example 2 -->
  <handler name="customxmlgenerator" type="request">
  
  <function>customgeneratexml</function>
  <location>customxmlgenerator.js</location>
  </handler>
  <!-- configuration for example 1 -->
  <form ajaxref="example1">
  <element ajaxref="button">
  <event type="onclick">
  <requesthandler type="std:querystring">
  <target>example1.do</target>
  <parameter>firstname=firstname,lastname=lastname</parameter>
  </requesthandler>
  <responsehandler type="std:innerhtml">
  <parameter>example1_resultlayer</parameter>
  </responsehandler>
  </event>
  </element>
  </form></ajaxconfig>
  
  在配置文件中定义了该表单的属性,以及按钮触发的事件和回写结果的处理方法。采用很巧妙的封装方法实现了struts的ajax调用。当然ajaxtags离实用阶段还有相对长的一段距离,但它提供了一种在现有的软件架构上高效率开发ajax应用程序的可行性方案。

扫描关注微信公众号