nv.jsp
使用javascript将下级菜单显示在页面上
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'nv.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type='text/javascript' src='/DwrTest/dwr/engine.js'></script>
<script type='text/javascript' src='/DwrTest/dwr/inte易做图ce/menuDao.js'></script>
<script type='text/javascript' src='/DwrTest/dwr/util.js'></script>
<script type="text/javascript">
var id;
var n;
function callBack(data) {
if(data.length>0){
var nvs=document.getElementById(id);
if(nvs.innerHTML.indexOf("DIV")>-1 || nvs.innerHTML.indexOf("div")>-1){
var divch=nvs.lastChild;
if(divch.style.display=='none'){
divch.style.display='block';
}else
{
divch.style.display='none';
}
}else{
var nvstr="<div>"+nvs.innerHTML+"</div>";
var spn="";
for(var j=0;j<n*2;j++){
spn=spn+" ";
}
n=n+1;
nvstr=nvstr+"<div>";
for(var i=0;i<data.length;i++){
nvstr=nvstr+"<div id='"+data[i].id+"'>"+spn+"<a href='javascript:void(0)' onclick='nvsClick("+data[i].id+","+n+")' >"+data[i].menuname+"</a></div>";
}
nvs.innerHTML=nvstr+"</div>";
}
}
}
function nvsClick(nvid,nu){
id=nvid;
n=nu;
menuDao.himenuDao(id,callBack);
}
</script>
</head>
<body>
<div>
<div id="0" style="display: block">
<a onclick="nvsClick(0,1)" href="javascript:void(0)">主菜单</a>
</div>
</div>
</body>
</html>
dwr.xml配置文件
配置好要使用的实现ajax类的类以及bean.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr30.dtd">
<dwr>
<allow>
<create creator="new" javascript="service">
<param name="class" value="dwr.Service" />
</create>
<create creator="new" javascript="menuDao">
<param name="class" value="dwr.MenuDao" />
</create>
<convert match="bean.User" converter="bean">
<param name="include" value="id,username,password"></param>
</convert>
<convert match="bean.Himenu" converter="bean">
<param name="include" value="id,menuname,displayref,parentMenu,systemClass,menuOreder"></param>
</convert>
</allow>
</dwr>
ajax实现类,让dwr生成的函数从这里获得菜单数据
package dwr;
import java.util.ArrayList;
import java.util.List;
import bean.Himenu;
public class MenuDao {
private List<Himenu> list=new ArrayList<Himenu>();
public MenuDao(){
<