代码如下
<%@ page contentType="text/html;charset=gb2312" %>
<% String Loginmessage=(String)session.getValue("login");
if(Loginmessage==null) {
%>
<script language=javascript>
window.location="refuse.jsp"
</script>
<% }
%>
<html>
<head>
<title>论坛</title>
</head>
<body bgcolor="Teal">
<%@ include file="top.html" %>
<p><b><font color="red">欢迎来到本书的论坛!
</font></b></p><%@ page language="java" import="java.sql.*";%><%
//<jsp:useBean id="workM" scope="page" class="sql.forum" /> Connection con;
Statement stmt;
String con_string="jdbc:mysql://localhost";
con_string=con_string+"/forum?user=root&password=password";
con=DriverManager.getConnection(con_string);
stmt=con.createStatement();
String sql1;
int pageNo;
ResultSet countrs;if(request.getParameter("page")==null) {
pageNo=1;
}
else {
pageNo=Integer.parseInt(request.getParameter("page"));
}//ResultSet countrs=workM.executeQuery("select count(*) as cnt from article");countrs=stmt.executeQuery("select count(*) as cnt from article");int totalRec=0;
if(countrs.next())
totalRec=countrs.getInt("cnt");
countrs.close();int pageLine=6;
int mod=totalRec%pageLine;
int page_left=0;
if(mod!=0)
page_left=1;
int pages=totalRec/pageLine+page_left;
%><%
out.print("<table border='2' style='color:white'>");
out.print("<tr><td>标题</td><td>发表人</td>");
out.print("<td>发表时间</td><td>回复数</td><td>点击数</td></tr>");
String serial;
String title;
String speaker;
Date providedate;
int reply;
int click;
int bottom=(pageNo-1)*6;
int top=pageNo*6+1;
String sql="select * from article where parent_no=0"
+" and serial_no>"+bottom+" and serial_no<"+top+" order by serial_no DESC";
ResultSet RS=stmt.executeQuery(sql);
int i=0;
while(RS.next()) {
i++;
out.print("<tr><td>");
serial=RS.getString("serial_no");
title=RS.getString("title");
speaker=RS.getString("speaker");
providedate=RS.getDate("provide_time");
reply=RS.getInt("reply_num");
click=RS.getInt("click_num");
showing(request,out,serial,title,speaker,providedate,reply,click,"Subject");ResultSet RS1=stmt.executeQuery("select * from article where parent_no="+serial+" order by serial_no");
while(RS1.next()) {
i++;
out.print("<tr><td>");
serial=RS1.getString("serial_no");
title=RS1.getString("title");
speaker=RS1.getString("speaker");
providedate=RS1.getDate("provide_time");
reply=RS1.getInt("reply_num");
click=RS1.getInt("click_num");
showing(request,out,serial,title,speaker,providedate,reply,click,"Re");
}
RS1.close();
}
out.print("</table>");
RS.close();
out.print("<p><br>共有发言"+totalRec+"条, 分为"+pages+"页显示<br>");
for(int j=1;j<=pages;j++) {
if(j%10==0) out.print("<br>");
out.print("<a href=forum.jsp?page="+j+">");
if(j==pageNo)
out.print("<font color='red'>"+j+"</font>");
else out.print(j);
out.print("</a> ");
}
%><%!
void showing(HttpServletRequest request,JspWriter out,String serial, String title,String speaker,Date providedate,int reply,int click,String ReSign)
throws IOException {
if(ReSign=="Subject") {
out.print("<a href=forumcontent.jsp?serial="+serial+">"+title+"</a>");
}
else {
out.print("Re:<a href=forumrecontent.jsp?serial="+serial+">"+title+"</a>");
}
out.print("<td><td>");
out.print(speaker);
out.print("<td><td>");
out.print(providedate);
out.print("<td><td>");
out.print(reply);
out.print("<td><td>");
out.print(click);
out.print("<td></tr>");
}
%>
<p align="center"><a href="addtopic.jsp" target="_self">我要增加新帖</a>
<a href="login/show.html">登录</a>
<a href="login/reg.html">注册</a>
<%@ include file="bottom.html" %>
</body>
</html>
但刷新了浏览器两次,得出不同的错误:
提示一:
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: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:156)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.lang.ClassNotFoundException: org.apache.jsp.forum_jsp
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:598)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.16提示二:
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: /forum.jsp(21,0) Unterminated <%@ page tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:511)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1433)
org.apache.jasper.compiler.Parser.parse(Parser.java:133)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:153)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.16不知错在哪里,可否详细透露下,刚刚学jsp,caibird一个
<%@ page contentType="text/html;charset=gb2312" %>
<% String Loginmessage=(String)session.getValue("login");
if(Loginmessage==null) {
%>
<script language=javascript>
window.location="refuse.jsp"
</script>
<% }
%>
<html>
<head>
<title>论坛</title>
</head>
<body bgcolor="Teal">
<%@ include file="top.html" %>
<p><b><font color="red">欢迎来到本书的论坛!
</font></b></p><%@ page language="java" import="java.sql.*";%><%
//<jsp:useBean id="workM" scope="page" class="sql.forum" /> Connection con;
Statement stmt;
String con_string="jdbc:mysql://localhost";
con_string=con_string+"/forum?user=root&password=password";
con=DriverManager.getConnection(con_string);
stmt=con.createStatement();
String sql1;
int pageNo;
ResultSet countrs;if(request.getParameter("page")==null) {
pageNo=1;
}
else {
pageNo=Integer.parseInt(request.getParameter("page"));
}//ResultSet countrs=workM.executeQuery("select count(*) as cnt from article");countrs=stmt.executeQuery("select count(*) as cnt from article");int totalRec=0;
if(countrs.next())
totalRec=countrs.getInt("cnt");
countrs.close();int pageLine=6;
int mod=totalRec%pageLine;
int page_left=0;
if(mod!=0)
page_left=1;
int pages=totalRec/pageLine+page_left;
%><%
out.print("<table border='2' style='color:white'>");
out.print("<tr><td>标题</td><td>发表人</td>");
out.print("<td>发表时间</td><td>回复数</td><td>点击数</td></tr>");
String serial;
String title;
String speaker;
Date providedate;
int reply;
int click;
int bottom=(pageNo-1)*6;
int top=pageNo*6+1;
String sql="select * from article where parent_no=0"
+" and serial_no>"+bottom+" and serial_no<"+top+" order by serial_no DESC";
ResultSet RS=stmt.executeQuery(sql);
int i=0;
while(RS.next()) {
i++;
out.print("<tr><td>");
serial=RS.getString("serial_no");
title=RS.getString("title");
speaker=RS.getString("speaker");
providedate=RS.getDate("provide_time");
reply=RS.getInt("reply_num");
click=RS.getInt("click_num");
showing(request,out,serial,title,speaker,providedate,reply,click,"Subject");ResultSet RS1=stmt.executeQuery("select * from article where parent_no="+serial+" order by serial_no");
while(RS1.next()) {
i++;
out.print("<tr><td>");
serial=RS1.getString("serial_no");
title=RS1.getString("title");
speaker=RS1.getString("speaker");
providedate=RS1.getDate("provide_time");
reply=RS1.getInt("reply_num");
click=RS1.getInt("click_num");
showing(request,out,serial,title,speaker,providedate,reply,click,"Re");
}
RS1.close();
}
out.print("</table>");
RS.close();
out.print("<p><br>共有发言"+totalRec+"条, 分为"+pages+"页显示<br>");
for(int j=1;j<=pages;j++) {
if(j%10==0) out.print("<br>");
out.print("<a href=forum.jsp?page="+j+">");
if(j==pageNo)
out.print("<font color='red'>"+j+"</font>");
else out.print(j);
out.print("</a> ");
}
%><%!
void showing(HttpServletRequest request,JspWriter out,String serial, String title,String speaker,Date providedate,int reply,int click,String ReSign)
throws IOException {
if(ReSign=="Subject") {
out.print("<a href=forumcontent.jsp?serial="+serial+">"+title+"</a>");
}
else {
out.print("Re:<a href=forumrecontent.jsp?serial="+serial+">"+title+"</a>");
}
out.print("<td><td>");
out.print(speaker);
out.print("<td><td>");
out.print(providedate);
out.print("<td><td>");
out.print(reply);
out.print("<td><td>");
out.print(click);
out.print("<td></tr>");
}
%>
<p align="center"><a href="addtopic.jsp" target="_self">我要增加新帖</a>
<a href="login/show.html">登录</a>
<a href="login/reg.html">注册</a>
<%@ include file="bottom.html" %>
</body>
</html>
但刷新了浏览器两次,得出不同的错误:
提示一:
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: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:156)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.lang.ClassNotFoundException: org.apache.jsp.forum_jsp
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:598)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.16提示二:
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: /forum.jsp(21,0) Unterminated <%@ page tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:511)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1433)
org.apache.jasper.compiler.Parser.parse(Parser.java:133)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:153)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.16不知错在哪里,可否详细透露下,刚刚学jsp,caibird一个
<%
// <jsp:useBean id="workM" scope="page" class="sql.forum" />用<%%>或用jsp标签,哪有这样搞的
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 117 in the jsp file: /forum.jsp
IOException cannot be resolved to a type
114:
115: <%!
116: void showing(HttpServletRequest request,JspWriter out,String serial, String title,String speaker,Date providedate,int reply,int click,String ReSign)
117: throws IOException {
118: if(ReSign=="Subject") {
119: out.print("<a href=forumcontent.jsp?serial="+serial+">"+title+"</a>");
120: }
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)那又错在哪里呢?
IOException cannot be resolved to a type
114:
115: <%!
116: void showing(HttpServletRequest request,JspWriter out,String serial, String title,String speaker,Date providedate,int reply,int click,String ReSign)
117: throws IOException {
118: if(ReSign=="Subject") {
119: out.print(" <a href=forumcontent.jsp?serial="+serial+">"+title+" </a>");
120: }
I think you should add a "import" in Page directive, for the "IOException" can't be recognized by the container. So you can do change it like this:
<%@ page contentType="text/html;charset=gb2312" import="java.io.*"%>