<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%
String strId = request.getParameter("id");
int id = Integer.parseInt(strId);Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where id = " + id);%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body><%
if(rs.next()) {
%> <table border="1">
<tr>
<td>ID</td>
<td><%=rs.getInt("id") %></td>
</tr>
<tr>
<td>Title</td>
<td><%=rs.getString("title") %></td>
</tr>
<tr>
<td>Content</td>
<td><%=rs.getString("cont") %></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>lomboz中的提示
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /ShowArticleDetail.jsp:107:
8: <%
9: String strId = request.getParameter("id");
10: int id = Integer.parseInt(strId);
11:
12: Class.forName("com.mysql.jdbc.Driver");
13: String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:415)
java.lang.Integer.parseInt(Integer.java:497)
org.apache.jsp.ShowArticleDetail_jsp._jspService(ShowArticleDetail_jsp.java:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.17
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%
String strId = request.getParameter("id");
int id = Integer.parseInt(strId);Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where id = " + id);%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body><%
if(rs.next()) {
%> <table border="1">
<tr>
<td>ID</td>
<td><%=rs.getInt("id") %></td>
</tr>
<tr>
<td>Title</td>
<td><%=rs.getString("title") %></td>
</tr>
<tr>
<td>Content</td>
<td><%=rs.getString("cont") %></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>lomboz中的提示
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /ShowArticleDetail.jsp:107:
8: <%
9: String strId = request.getParameter("id");
10: int id = Integer.parseInt(strId);
11:
12: Class.forName("com.mysql.jdbc.Driver");
13: String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:415)
java.lang.Integer.parseInt(Integer.java:497)
org.apache.jsp.ShowArticleDetail_jsp._jspService(ShowArticleDetail_jsp.java:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.17
9: String strId = request.getParameter("id");
10: out.print(strId);
11: int id = Integer.parseInt(strId);
12: out.print(id);
13:
14: Class.forName("com.mysql.jdbc.Driver");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause 还是打印不出来 还在报数字格式错误 纠结啊 今天找了好久 还卡在这里动不了 唉
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@page import="java.sql.*" %>
<%
/**
1.首先连接数据库;
2.执行查找语句 executeQuery("select * from article")放入 ResulSet rs;
3.关闭打开的资源;
4.对查找出来的东西进行展现
(经验:在使用jsp和html展现时要注意要成对出现,在时间允许的情况下尽量把页面做得好看点!)
5.用递归的方法对内容进行展现15行开始是方法的声明和定义
6.把html当成字符串进行输出
7.给标题加上连接
**/
%>
<%!
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='ShowArticleDetail.jsp?id ="+ rs.getInt("id")+"'>"
+rs.getString("title")+"</td></tr>"+"</a>";
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/bbs?user=root&password=root";
Connection conn =DriverManager.getConnection(url);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='ShowArticleDetail.jsp?id ="+ rs.getInt("id")+"'>"
+rs.getString("title")+"</td></tr>"+"</a>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"),1);
}
}
rs.close();
stmt.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>Insert title here</title>
</head>
<body>
<table border="1">
<%=str %>
</table>
</body>
</html>这是第二个jsp是从上面一个jsp中取得id的
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%
String strId = request.getParameter("id");
int id = Integer.parseInt(strId);Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where id = " + id);%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body><%
if(rs.next()) {
%><table border="1">
<tr>
<td>ID</td>
<td><%=rs.getInt("id") %></td>
</tr>
<tr>
<td>Title</td>
<td><%=rs.getString("title") %></td>
</tr>
<tr>
<td>Content</td>
<td><%=rs.getString("cont") %></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>lomboz中的提示
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /ShowArticleDetail.jsp:107:
8: <%
9: String strId = request.getParameter("id");
10: int id = Integer.parseInt(strId);
11:
12: Class.forName("com.mysql.jdbc.Driver");
13: String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:415)
java.lang.Integer.parseInt(Integer.java:497)
org.apache.jsp.ShowArticleDetail_jsp._jspService(ShowArticleDetail_jsp.java:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.17