Ajax in Struts: implementing dependent select boxes
来源:互联网 发布:linux将文件夹压缩 编辑:程序博客网 时间:2024/04/28 05:43
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);
//清除缓存
- Ajax in Struts: implementing dependent select boxes
- Implementing Ajax in Java web application using JQuery
- Implementing Apriori Algorithm in
- Boxes in a Line
- Implementing Reverse Proxy in Squid
- Implementing Enumerable & Enumerator in Ruby
- Implementing SoD in SQL Server
- Implementing MP3 player in C
- Implementing Apriori Algorithm in R
- 混沌 IN C++::Argument Dependent Lookup
- Missed Signals : state-dependent in concurrent
- 12657-Boxes in a Line
- UVa12657 Boxes in a Line
- uva12657 boxes in a line
- 12657 Boxes in a Line
- uva12657 Boxes in a Line
- 12657 - Boxes in a Line
- Uva12657 Boxes in a line
- 个人技术能力描述
- wm_concat,行转列的好东东
- global max_allowed_packet=67108864
- ShellExecute(Ex) 运行带空格命令行
- WPF学习个人博客收录
- Ajax in Struts: implementing dependent select boxes
- sqldatareader ,sqldataadaper 区别,奥耶
- 开放平台其实是一种B2B模式
- 一条查询某一条数据是整个表中的第几条数据的SQL
- BIN文件与NB0的区别
- 《Microsoft Sql server 2008 Internals》读书笔记--第三章Databases and Database Files(2)
- Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex
- Gridview控件添加编辑按钮时候需编写的函数》
- ImportError: No module named vtkCommonPython