我想创建一个Jsp动态菜单数据是从数据库获取的.buti只能访问一个菜单,这里是我的代码和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>
谢谢
答案 0 :(得分:0)
我认为问题可能在这里:
ResultSet rs2 = st1.executeQuery(query2); // Still st1?
将其更改为st2.executeQuery(query2)并尝试。