我想把发表新帖这一连接加在jsp页面里面可是运行之后显示不了,我是菜鸟,希望高手帮忙!谢谢了啊……
<%@ 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 stat=null;
ResultSet rs=null;
String preStr="";
for(int i=0;i<level;i++){
preStr+="--";
}
try{
stat=conn.createStatement();
String sql="select * from article where pid= "+id;
rs=stat.executeQuery(sql);
while(rs.next()){
int ids=rs.getInt("id");
int pid=rs.getInt("pid");
str+="<tr><td>"+ids+"</td><td>"+
preStr+"<a href='ShowArticleDetial.jsp?id="+ids+"'>"+rs.getString("title")+"</a></td><td>"+
"<a href='Delete.jsp?id="+id+"&pid="+pid+"'>"+"删除"+"<a></td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,ids,level+1);
}
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stat!=null){
stat.close();
stat=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
%>
<%
Connection conn=null;
Statement stat=null;
ResultSet rs=null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bbs";
conn=DriverManager.getConnection(url,"sa","sa");
stat=conn.createStatement();
rs=stat.executeQuery("select *from article where pid=0");
while(rs.next()){
int ids=rs.getInt("id");
int pid=rs.getInt("pid");
str+="<tr><td>"+ids+"</td><td>"+
"<a href='ShowArticleDetial.jsp?id="+ids+"'>"
+rs.getString("title")+"</td><td>"+
"<a href='Delete.jsp?id="+ids+"&pid="+pid+"'>"+"删除"+"</a></td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,ids,1);
}
}
rs.close();
stat.close();
conn.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>树形</title>
</head>
<body>
<a href="Delete.jsp">发表新帖</a> <table border="1">
<%=str%>
<% str="";%>
</table>
</body>
</html>
<%@ 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 stat=null;
ResultSet rs=null;
String preStr="";
for(int i=0;i<level;i++){
preStr+="--";
}
try{
stat=conn.createStatement();
String sql="select * from article where pid= "+id;
rs=stat.executeQuery(sql);
while(rs.next()){
int ids=rs.getInt("id");
int pid=rs.getInt("pid");
str+="<tr><td>"+ids+"</td><td>"+
preStr+"<a href='ShowArticleDetial.jsp?id="+ids+"'>"+rs.getString("title")+"</a></td><td>"+
"<a href='Delete.jsp?id="+id+"&pid="+pid+"'>"+"删除"+"<a></td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,ids,level+1);
}
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stat!=null){
stat.close();
stat=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
%>
<%
Connection conn=null;
Statement stat=null;
ResultSet rs=null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bbs";
conn=DriverManager.getConnection(url,"sa","sa");
stat=conn.createStatement();
rs=stat.executeQuery("select *from article where pid=0");
while(rs.next()){
int ids=rs.getInt("id");
int pid=rs.getInt("pid");
str+="<tr><td>"+ids+"</td><td>"+
"<a href='ShowArticleDetial.jsp?id="+ids+"'>"
+rs.getString("title")+"</td><td>"+
"<a href='Delete.jsp?id="+ids+"&pid="+pid+"'>"+"删除"+"</a></td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,ids,1);
}
}
rs.close();
stat.close();
conn.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>树形</title>
</head>
<body>
<a href="Delete.jsp">发表新帖</a> <table border="1">
<%=str%>
<% str="";%>
</table>
</body>
</html>
好像tomcat里面的jsp不能及时的跟新跟来一样,我把MyEclipse里面的复制到tomcat的工作区间里面问题就解决了!