In this posting, I want to explain how I have made use of AJAX in a Struts application
On my current project, I’m building a Struts-based web application with many input forms. Many of these forms contain two or more dependable html select boxes. This means, when you have two dependable boxes, that the available options in the second selectbox depends on the value selected in the first selectbox. To do this there are three possible solutions:
- Use javascript arrays, where each set of options links to an option in the first select-box
- Use an onchange on the first select box to automatically submit the form to go back to the server, collect the new options for the second box and regenerate the whole page
- Use Ajax to asynchronously retrieve the new options for the second box
The first option is not what we wanted: it means that we have to implement a lot of logic in the html-page, which is visible to the outside world and in common javascript isn’t the easiest language to debug . The second option is better, but has the big disadvantage that you have to do a complete round trip to the server to collect the new options and after that the whole page is regenerated again where actually only the second box is updated..a lot of overhead..
So we decided to use AJAX to solve our problem of dependend select-boxes.
Because Struts does not have AJAX support yet (wait for Shale..) we have to add it ourselves. Because AJAX is not a framework but just a technique to make webpages more dynamic using Javascript and DHTML, it is quite easy to use it in combination with struts.
First we make a small html form:
Now we have to implement our javascript part:
Finally, we have to implement the Struts Action:
注:
会出现responseText 不能刷新,可在java代码中加入
//清除缓存
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires", 0);
//清除缓存
分享到:
相关推荐
读书笔记:Implementing DomainDriven Design 实现领域驱动设计 代码示例
读书笔记:Implementing.DomainDriven.Design实现领域驱动设计 中英文对照翻译
Information Retrieval Implementing and Evaluating Search Engines Stefan B¨uttcher Charles L. A. Clarke Gordon V. Cormack
The book "BigNum Math: Implementing Cryptographic Multiple Precision Arithmetic" serves as an invaluable resource for students and practitioners interested in developing robust cryptographic systems....
行业报告
Wiley - Implementing NAP and NAC Security Technologies(Apr 2008).pdf
Programming Assignment 5: Implementing a Reliable Transport Protocol In this laboratory programming assignment, you will be writing the sending and receiving transport-level code for implementing a ...
VMware vRealize Automation Handbook Implementing Cloud Management in the Enterprise Environment 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索...
Android User Interface Design Implementing Material Design for Developers(2nd) 英文epub 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Android User Interface Design Implementing Material Design for Developers(2nd) 英文mobi 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
You’ll learn techniques for implementing specific Web technologies and patterns to solve the needs of a typical company as it grows from modest beginnings to become a global enterprise. Learn basic ...
### Ajax in Action: Key Insights and Concepts "Ajax in Action" is an authoritative guide for programmers with some experience in web development. The book is structured into four parts, each ...
根据提供的文件内容,我们可以提炼出以下知识点: 1. Android用户界面设计: 本书专注于Android平台的用户界面设计,特别是Material Design(材质设计)的实现方法,这是一套由Google设计和推广的设计语言,旨在为...
CCNA+CCNP(From 2007-4-7 To 2007-5-4--Friday(5.4)) Teached by MR. MA CCNP+ (From 2007-6-1 TO 2007-7-7) Teached by MR. Chen CCIE Service Provider(SP) (From 2007-7-... 642-611 MPLS: Implementing Cisco MPLS
超越BIOS。 这两个词开始流经精英阶层 固件架构师和行业标准计算开发人员 围绕着1998年的时候,当时英特尔,微软,惠普等一批人 公司开始制定第一个英特尔®安腾®处理器的计划 ®系统。 该计划最初称为英特尔启动...
### 实现功能语言:教程 #### 一、引言 《实现功能语言:教程》是一本专注于非严格功能语言实现的书籍,它提供了一种基于惰性图归约的实用方法来理解和实施这类语言。本书适合对计算机科学尤其是函数式编程领域感...
Title: Implementing Cloud Design Patterns for AWS Author: Marcus Young Length: 234 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2015-05-15 ISBN-10: 1782177345 ISBN-...
Beyond BIOS 第三版 Beyond.BIOS.Developing.with.the.Unified.Extensible.Firmware.Interface.3rd.Editio