See some examples on the internet, for a simple three-level linkage, plus what struts, hibernate, and so on. This Ajax linkage does not know what the relationship with these frameworks, a small demo why the whole so big.
Today, I did an example of dwr+jsp.
Xml:
Copy Code code as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.4" xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
Org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>SelectServlet</servlet-name>
<servlet-class>com.action.SelectServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SelectServlet</servlet-name>
<url-pattern>/select</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Dwr.xml:
Copy Code code as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE dwr Public "-//getahead limited//dtd Direct Web Remoting
2.0//en "HTTP://WWW.GETAHEAD.LTD.UK/DWR/DWR20.DTD" >
<dwr>
<!--can't do anything without it--> DWR
<allow>
<create creator= "New" javascript= "menu" >
<param name= "class" value= "Com.dao.CountryDAO"/>
</create>
<!--the Bean--> to convert
<convert converter= "Bean" match= "com.vo.Country"/>
<convert converter= "Bean" match= "com.vo.Province"/>
<convert converter= "Bean" match= "com.vo.City"/>
</allow>
</dwr>
TEST.JSP:
Copy Code code as follows:
<%@ page language= "java" import= "java.util.*,com.vo.*"
pageencoding= "GBK"%>
<%@ taglib uri= "Http://java.sun.com/jstl/core" prefix= "C"%>
<title>dwr three-level linkage </title>
<script type= ' Text/javascript '
Src= '/mutiplymenu/dwr/interface/menu.js ' ></script>
<script type= ' text/javascript ' src= '/mutiplymenu/dwr/engine.js ' ></script>
<script type= ' text/javascript ' src= '/mutiplymenu/dwr/util.js ' ></script>
<body>
<script type= "Text/javascript" >
According to the country ID to check the province or state
function Queryprovince ()
{
var Countryid = $ ("country"). Value;
Default is not selected
if (Countryid = 0)
{
${"province"}.options.length=0;
${"City"}.options.length=0;
}
Else
{
Menu.queryprovincebyid (Countryid,provincecallback);
}
}
To query for a callback function in a province or state based on a country ID
function Provincecallback (provinces)
{
${"province"}.options.length=0;
Each time the new data is obtained, the length of each two drop frame is cleared 0
for (Var i=0;i< provinces.length;i + +) {
var value = provinces[i].id;
var text = Provinces[i].provincename;
var option = new option (text, value);
Create an Option object based on the values of each group of value and text tags
try{
$ ("province"). Add (option);//Adds the option object to the second Drop-down box
}catch (e) {
}
}
Associate the third level at the same time
var Provinceid = ${"province"}.value;
Menu.querycitybyid (Provinceid,citycallback);
}
Query the city you belong to
function querycity ()
{
var Provinceid = $ ("province"). Value;
Menu.querycitybyid (Provinceid,citycallback);
}
Query the owning city callback function
function Citycallback (citys)
{
Each time the new data is obtained, the length of each three drop frame is cleared 0
${"City"}.options.length=0;
for (Var i=0;i< citys.length;i + +) {
var value = citys[i].id;
var text = Citys[i].cityname;
var option = new option (text, value);
Create an Option object based on the values of each group of value and text tags
try{
$ ("City"). Add (option);//Option Object added to third Drop-down box
}catch (e) {
}
}
}
function Change1 ()
{
Queryprovince ();
}
function Change2 ()
{
Querycity ();
}
</script>
<div align= "center" >
<br>
DWR three-level linkage demo
<!--I'm surprised that my <c> tags can't be used here-->
<select id= "Country" onchange= "change1 ();" >
<option selected= "selected" value= "0" >
Please select
</option>
<%
@SuppressWarnings ("Unchecked")
List List = (list) request.getattribute ("Countrys");
for (int i = 0; i < list.size (); i++)
{
Country temp = (Country) list.get (i);
%>
<option value= "<%=temp.getid ()%>" ><%=temp.getcountryname ()%></option>
<%
}
%>
</select>
<select id= "province" onchange= "Change2 ();" >
</select>
<select id= "City" >
</select>
</div>
</body>
Servlet,dao will not post, want to know can download the source code