本人在java中动态生成菜单树的html格式的在jsp中打开不了二级菜单问题
本人在java中动态生成菜单树的html格式的在jsp中打开不了二级菜单问题,但把动态生成的html格式的菜单树,手工放在jsp中,确可以打开二级菜单,有谁知道原因不?jsp页面:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="../css/common.css" type="text/css" />
<title>左侧导航栏</title>
<script src="../js/jquery-1.10.2.min.js"></script>
</head>
<body>
<div id="left_content">
<div class="Department Menu">
<ul id="Menu_ul">
</ul>
</div>
</div>
</body>
<script language="javascript" type="text/javascript">
//Menu_Current 首级菜单
$(document).ready(function(e) {
$("#Menu_ul>li").on("click",function(){
$(this).siblings().removeClass("Menu_Current");
$(this).addClass("Menu_Current");
});
});
//二级菜单
$(document).ready(function(e) {
$("#Menu_ul ul").on("click","li",function(e){
$(this).siblings().removeClass("active");
$(this).addClass("active");
});
});
$(document).ready(function(e) {
$.post("<%=basePath%>/employee/menu.action",function(data){
if(data!=null){
var listmenu = data.resultmenu;
$("#Menu_ul").html(listmenu);
alert(listmenu);
}
});
});
</script>
java 代码:
/**
* 获取菜单
* @return
*/
public String menu(){
try{
//String pid=request.getParameter("pid");
List<Role> listrole=(List<Role>)session.get("employeerole");
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//取一级菜单
listmenu=roleService.getrole_menu(listrole,"0");
String str="";
if(listmenu.size()>0){
for(int i=0;i<listmenu.size();i++){
listmenutwo=roleService.getrole_menu(listrole,listmenu.get(i).getMenuid()+"");
if(listmenutwo.size()>0){
if(listmenu.get(i).getLinkaddress()!=null && !listmenu.get(i).getLinkaddress().equals("")){
str+="<li><a href='"+basePath+""+listmenu.get(i).getLinkaddress()+"' target='mainFrame'>"+listmenu.get(i).getMenuname()+"</a>";
}else{
str+="<li><a href='javascript:void(0)' target='mainFrame'>"+listmenu.get(i).getMenuname()+"</a>";
}
//str+="<div class=Two ><ul class=Two_ul>";
str+=" <ul>";
for(int j=0;j<listmenutwo.size();j++){
if(listmenutwo.get(j).getLinkaddress()!=null && !listmenutwo.get(j).getLinkaddress().equals("")){
str+="<li><a href='"+basePath+""+listmenutwo.get(j).getLinkaddress()+"' target='mainFrame'>"+listmenutwo.get(j).getMenuname()+"</a></li>";
}else{
str+="<li><a href='javascript:void(0)' target='mainFrame'>"+listmenutwo.get(j).getMenuname()+"</a> </li>";
}
}
//str+="</ul></div>";
str+=" </ul> </li>";
}else{
if(listmenu.get(i).getLinkaddress()!=null && !listmenu.get(i).getLinkaddress().equals("")){
str+="<li><a href='"+basePath+""+listmenu.get(i).getLinkaddress()+"' target='mainFrame'>"+listmenu.get(i).getMenuname()+"</a></li>";
}else{
str+="<li><a href='javascript:void(0)' target='mainFrame'>"+listmenu.get(i).getMenuname()+"</a></li>";
}
}
}
}
resultmenu=str;
//if(pid.equals("0")){
//listmenu=roleService.getrole_menu(listrole,pid);
//}else{
//listmenutwo=roleService.getrole_menu(listrole,pid);
//}
}catch(Exception e){
e.printStackTrace();
}
return SUCCESS;
} --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 代码那么长。你一点一点加功能,不定是哪里引入的 bug
补充:Java , Web 开发