jsp在Eclipse里加超連結無反應,請教各位

sway發表於2008-08-10
原始碼如下:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>

<%! String str = "";
private void tree(Connection conn,int id,int level) {
Statement stmt = null;
ResultSet rs = null;
String preStr = "";

for(int i=0; i<level; i++) {
preStr += "----";
}

try {
stmt = conn.createStatement();
String sql = "select * from article where pid = " + id;
rs = stmt.executeQuery(sql);
while(rs.next()) {
str += "<tr><td>" + rs.getInt("id") +"</td><td>" +
preStr + "<a href='ShowArticleDetails.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") +
"</a><td>" +
"<a href='Delete.jsp?id=" + rs.getInt("id") +"&pid=" +
rs.getInt("pid") + "'>Delete</td></a>" +
"</td></tr>";
if(rs.getInt("isleaf") != 0) {
tree(conn,rs.getInt("id"),level +1);
}
}
}catch(SQLException e) {
e.printStackTrace();
}finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
}catch(SQLException e) {
e.printStackTrace();
}
}
}
%>

<%
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/bbs";
Connection conn = DriverManager.getConnection(url,"root","root");

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0");

while(rs.next()) {
str += "<tr><td>" + rs.getInt("id") +"</td><td>" +
"<a href='ShowArticleDetails.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") +
"</a><td>" +
"<a href='Delete.jsp?id=" +
rs.getInt("id") + "&pid=" +rs.getInt("pid") +"'>Delete</a></td>" +
"</td></tr>";
if(rs.getInt("isleaf") != 0) {
tree(conn,rs.getInt("id"),1);
}
}
rs.close();
stmt.close();
conn.close();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Show Article Tree</title>
</head>
<body>
<a href="Post.jsp">Post new subject</a> // 我想在此處加一個連結,但怎麼加都沒反應
<table border="2"> // 忙活了我一下午
<%= str %>
<% str = ""; %>
</table>
</body>
</html>

麻煩如上文,本人系新手一個,求大家幫助幫助。

相關文章