<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %><%
String admin = (String)session.getAttribute("admin");
if(admin != null && admin.equals("true")) {
login = true;
}
%><%!
String str = "";
boolean login = false;
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);
String strLogin = "";
while(rs.next()) {
if(login) {
strLogin = "<td><a href='Delete.jsp?id=" + rs.getInt("id") + "&pid=" + rs.getInt("pid") + "'>删除</a>";
}
str += "<tr><td>" + rs.getInt("id") + "</td><td>" +
preStr + "<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") + "</a></td>" +
strLogin +
"</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/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0");
String strLogin = "";
while(rs.next()) {
if(login) {
strLogin = "<td><a href='Delete.jsp?id=" + rs.getInt("id") + "&pid=" + rs.getInt("pid") + "'>删除</a>";
}
str += "<tr><td>" + rs.getInt("id") + "</td><td>" +
"<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") + "</a></td>" +
strLogin +
"</td></tr>";
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>
<a href="Post.jsp">发表新帖</a>
<table border="1">
<%= str %>
<%
str = "";
login = false;
%>
</table>
</body></html>这我第一个JSP,类名ShowArticleTree<%@ 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>
<a href="Reply.jsp?id=<%= rs.getInt("id")%>&rootid=<%=rs.getInt("rootid") %>">回复</a>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>这是第2个JSP,类名 ShowArticleDetail
create database bbs;use bbs;create table article
(
id int primary key auto_increment,
pid int,
rootid int,
title varchar(255),
cont text,
pdate datetime,
isleaf int
);insert into article values (null, 0, 1, '蚂蚁大战大象', '蚂蚁大战大象', now(), 1);
insert into article values (null, 1, 1, '大象被打趴下了', '大象被打趴下了',now(), 1);
insert into article values (null, 2, 1, '蚂蚁也不好过','蚂蚁也不好过', now(), 0);
insert into article values (null, 2, 1, '瞎说', '瞎说', now(), 1);
insert into article values (null, 4, 1, '没有瞎说', '没有瞎说', now(), 0);
insert into article values (null, 1, 1, '怎么可能', '怎么可能', now(), 1);
insert into article values (null, 6, 1, '怎么没有可能', '怎么没有可能', now(), 0);
insert into article values (null, 6, 1, '可能性是很大的', '可能性是很大的', now(), 0);
insert into article values (null, 2, 1, '大象进医院了', '大象进医院了', now(), 1);
insert into article values (null, 9, 1, '护士是蚂蚁', '护士是蚂蚁', now(), 0);引进MySQL数据库的表单,谁方便的话帮我调试一下 。告诉我问题出在哪?我在运行第2个JSP时出现下面的提示
org.apache.jasper.JasperException: Exception in JSP: /ShowArticleDetail.jsp:7 4: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5: <%
6: String strId = request.getParameter("id");
7: int id = Integer.parseInt(strId);
8:
9: Class.forName("com.mysql.jdbc.Driver");
10: String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
root cause java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
org.apache.jsp.ShowArticleDetail_jsp._jspService(ShowArticleDetail_jsp.java:48)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %><%
String admin = (String)session.getAttribute("admin");
if(admin != null && admin.equals("true")) {
login = true;
}
%><%!
String str = "";
boolean login = false;
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);
String strLogin = "";
while(rs.next()) {
if(login) {
strLogin = "<td><a href='Delete.jsp?id=" + rs.getInt("id") + "&pid=" + rs.getInt("pid") + "'>删除</a>";
}
str += "<tr><td>" + rs.getInt("id") + "</td><td>" +
preStr + "<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") + "</a></td>" +
strLogin +
"</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/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0");
String strLogin = "";
while(rs.next()) {
if(login) {
strLogin = "<td><a href='Delete.jsp?id=" + rs.getInt("id") + "&pid=" + rs.getInt("pid") + "'>删除</a>";
}
str += "<tr><td>" + rs.getInt("id") + "</td><td>" +
"<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") + "</a></td>" +
strLogin +
"</td></tr>";
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>
<a href="Post.jsp">发表新帖</a>
<table border="1">
<%= str %>
<%
str = "";
login = false;
%>
</table>
</body></html>这我第一个JSP,类名ShowArticleTree<%@ 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>
<a href="Reply.jsp?id=<%= rs.getInt("id")%>&rootid=<%=rs.getInt("rootid") %>">回复</a>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>这是第2个JSP,类名 ShowArticleDetail
create database bbs;use bbs;create table article
(
id int primary key auto_increment,
pid int,
rootid int,
title varchar(255),
cont text,
pdate datetime,
isleaf int
);insert into article values (null, 0, 1, '蚂蚁大战大象', '蚂蚁大战大象', now(), 1);
insert into article values (null, 1, 1, '大象被打趴下了', '大象被打趴下了',now(), 1);
insert into article values (null, 2, 1, '蚂蚁也不好过','蚂蚁也不好过', now(), 0);
insert into article values (null, 2, 1, '瞎说', '瞎说', now(), 1);
insert into article values (null, 4, 1, '没有瞎说', '没有瞎说', now(), 0);
insert into article values (null, 1, 1, '怎么可能', '怎么可能', now(), 1);
insert into article values (null, 6, 1, '怎么没有可能', '怎么没有可能', now(), 0);
insert into article values (null, 6, 1, '可能性是很大的', '可能性是很大的', now(), 0);
insert into article values (null, 2, 1, '大象进医院了', '大象进医院了', now(), 1);
insert into article values (null, 9, 1, '护士是蚂蚁', '护士是蚂蚁', now(), 0);引进MySQL数据库的表单,谁方便的话帮我调试一下 。告诉我问题出在哪?我在运行第2个JSP时出现下面的提示
org.apache.jasper.JasperException: Exception in JSP: /ShowArticleDetail.jsp:7 4: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5: <%
6: String strId = request.getParameter("id");
7: int id = Integer.parseInt(strId);
8:
9: Class.forName("com.mysql.jdbc.Driver");
10: String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
root cause java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
org.apache.jsp.ShowArticleDetail_jsp._jspService(ShowArticleDetail_jsp.java:48)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
解决方案 »
- 求救 struts2.3.1 类型转换异常
- 谁会部署开源Java博客Roller v5.0 for Tomcat?
- struts2 使用DomainModel自动封装form值的问题
- 对于非计算机专业的学生,想要进入这个行业的话,除了java ee或.net外
- 关于xml的一些信息不太懂
- 急!系统在windows下运行正常,linux下运行报错~~~~~~~
- 关于TOMCAT配置SSL问题
- java ee 加上web.xml的配置后启动tomcat报错
- eclipse项目按右键刷新时总弹出这个错误
- CMP2.0发布时JNDI的问题
- EJB3.0方法调用的性能问题
- 多线程操作数据库连接池引起的内存泄露
-----------------------------------
打印strId看一下是不是null
要先判断一下strId是否为null
如
if(strId!=null){
int id = Integer.parseInt(strId);
}
试试这样行不行
我也出现过这样的问题,我用上面的可以啦,我也不明白
理论上应该是你写的那样:
String strId = request.getParameter("id");
int id = Integer.parseInt(strId);
7: int id = Integer.parseInt(strId);
8: strId是个空,
extends IllegalArgumentException
当应用程序试图将字符串转换成一种数值类型,但该字符串不能转换为适当格式时,抛出该异常。
看楼上问你的
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %> <%
String admin = (String)session.getAttribute("admin");
if(admin != null && admin.equals("true")) {
login = true;
}
%> <%!
String str = "";
boolean login = false;
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);
String strLogin = ""; while(rs.next()) {
if(login) {
strLogin = " <td> <a href='Delete.jsp?id=" + rs.getInt("id") + "&pid=" + rs.getInt("pid") + "'>删除 </a>";
}
str += " <tr> <td>" + rs.getInt("id") + " </td> <td>" +
preStr + " <a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") + " </a> </td>" +
strLogin +
" </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/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0");
String strLogin = "";
while(rs.next()) {
if(login) {
strLogin = " <td> <a href='Delete.jsp?id=" + rs.getInt("id") + "&pid=" + rs.getInt("pid") + "'>删除 </a>";
}
str += " <tr> <td>" + rs.getInt("id") + " </td> <td>" +
" <a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
rs.getString("title") + " </a> </td>" +
strLogin +
" </td> </tr>";
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>
<a href="Post.jsp">发表新帖 </a>
<table border="1">
<%= str %>
<%
str = "";
login = false;
%>
</table>
</body> </html>
第二个JSP:ShowArticleDetail <%@ 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>
<a href="Reply.jsp?id= <%= rs.getInt("id")%>&rootid= <%=rs.getInt("rootid") %>">回复 </a>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html> java.lang.NumberFormatException: null 这个错误可能是你在String strId = request.getParameter("id"); //这里如果没有传递过来的话就会是个null
//在使用strId之前最好加个null判断
int id = Integer.parseInt(strId); //对null进行转换就会报NumberFormatException
做下非空判断