Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jsp动态菜单是否仅显示一项及其子项?_Jsp - Fatal编程技术网

jsp动态菜单是否仅显示一项及其子项?

jsp动态菜单是否仅显示一项及其子项?,jsp,Jsp,我想创建一个Jsp动态菜单,数据是从数据库中获取的。但是我只能访问一个菜单,这里是我的代码和css <style>ul { font-family: Arial, Verdana; font-size: 14px; margin: 0; padding: 0; list-style: none; } ul li {

我想创建一个Jsp动态菜单,数据是从数据库中获取的。但是我只能访问一个菜单,这里是我的代码和css

<style>ul {
            font-family: Arial, Verdana;
            font-size: 14px;
            margin: 0;
            padding: 0;
            list-style: none;
            }
            ul li {
            display: block;
            position: relative;
            float: left;
            }
            li ul {
            display: none;
            }
            ul li a {
            display: block;
            text-decoration: none;
            color: #ffffff;
            border-top: 1px solid #ffffff;
            padding: 5px 15px 5px 15px;
            background: #2C5463;
            margin-left: 1px;
            white-space: nowrap;
            }
            ul li a:hover { background: #617F8A; }
            li:hover ul {
            display: block;
            position: absolute;
            }
            li:hover li {
            float: none;
            font-size: 14px;
            }
            li:hover a { background: #617F8A; }
            li:hover li a:hover { background: #95A9B1; }
            ul li.next {
            position: absolute;
            display: block;
            float: left; 
            background:#E8E8E8;
            font-size: 14px;
            border-top: 1px solid #ffffff;
            padding: 5px 15px 5px 15px;
            }
            ul li a.first {
            background: #617F8A;
            } 
         </style>
           </head>
           <body>
               <div>
                   <%
                    //String connectionURL="jdbc:mysql://localhost:3306/dairy";
                        ArrayList list = new ArrayList();
                        ArrayList sublist = new ArrayList();
                         JSONArray jArray = new JSONArray();
                        try {
                            //Class.forName("oracle.jdbc.OracleDriver");  
                            Class.forName("com.mysql.jdbc.Driver").newInstance();
                            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
                    %>
                   <ul>
                       <%
                            String query1 = "select countryname,countryid  from country";
                            Statement st1 = con.createStatement();
                            ResultSet rs1 = st1.executeQuery(query1);

                            while (rs1.next()) {
                               //for(rs1.size)
                                //out.println(rs1.size());
                         %>
                       <li>
                           <a href="#">

                               <%= rs1.getString(1)%>


                           </a>
                           <ul>
                               <%
                                    String query2 = "select state from state where countryid='" + rs1.getString(2) + "'";
                                    Statement st2 = con.createStatement();
                                    ResultSet rs2 = st1.executeQuery(query2);
                                    while (rs2.next()) {
                                %>
                               <li>
                                   <a href="#">
                                       <%= rs2.getString(1) %>
                                   </a>
                               </li>
                               <%
                                    }
                                %>
                           </ul>
                       </li>
                       <%
                            }
                        %>
                   </ul>
                   <%
                                   } catch (Exception e1) {
                        }
                    %>
                   <%
                    %>
               </div>  
           </body>
ul{
字体系列:Arial,Verdana;
字体大小:14px;
保证金:0;
填充:0;
列表样式:无;
}
ulli{
显示:块;
位置:相对位置;
浮动:左;
}
李乌尔{
显示:无;
}
ullia{
显示:块;
文字装饰:无;
颜色:#ffffff;
边框顶部:1px实心#ffffff;
填充:5px15px 5px 15px;
背景:#2C5463;
左边距:1px;
空白:nowrap;
}
ul li a:悬停{背景:#617F8A;}
李:悬停{
显示:块;
位置:绝对位置;
}
李:停下来,李{
浮动:无;
字体大小:14px;
}
李:将鼠标悬停在{背景:#617F8A;}
li:hover li a:hover{background:#95A9B1;}
下一个{
位置:绝对位置;
显示:块;
浮动:左;
背景:#E8E8E8;
字体大小:14px;
边框顶部:1px实心#ffffff;
填充:5px15px 5px 15px;
}
首先是李安{
背景#617F8A;
} 

谢谢

我想问题可能出在这里:

ResultSet rs2 = st1.executeQuery(query2);  // Still st1?

将其更改为st2.executeQuery(query2)并试一试。

我可以在子菜单下再次创建子菜单吗?当然搜索“twitter引导”并查看一些示例。基本上,这就是使用HTML可以做到的。