以下是主页面的文件index.jsp:
<HTML><HEAD><TITLE></TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<LINK href="css/site.css" rel=stylesheet>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<script language="javascript" src="../js/all.js">
</script>
<%@ include file="header.inc"%>
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="workM" scope="page" class="test.faq" />
<TABLE border=0 cellPadding=0 cellSpacing=0 width=760 align="center">
<TBODY>
<tr><td align="left" height=25>当前位置:<a href="index.jsp">首页</a> </td>
<%@ include file="date.inc"%>
</tr>
<TR bgColor=#3399ff>
<TD height=1 colspan="6"><IMG height=1 src="../../images/code.gif"
width=16></TD></TR>
<tr><td height=10 colspan="6"><IMG height=1 src="../../images/execute.gif"
width=16></td></tr>
</TBODY></TABLE>
<table align="center" border="0" width="760" cellspacing="0" cellpadding="0" height="355">
<tr>
<td width="150" height="355" valign="top">
<%@ include file="table.inc"%>
</td>
<td width="10" height="100%"></td>
<td width="1" height="100%" bgcolor="#3399ff"></td>
<td width="10" height="100%"></td>
<td width="589" height="331" valign="top" background="images/bg1.gif">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="307">
<tr>
<td width="100%" height="20" bgcolor="">
<a href="mailto:[email protected]">最新动态</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%@ include file="footer.inc"%>以下是讨论区的主页面文件:
<HTML><HEAD><TITLE></TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<LINK href="css/site.css" rel=stylesheet>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<script language="javascript" src="../js/all.js">
</script>
<%@ include file="header.inc"%>
<%@ page language="java" import="java.sql.*" %>
<%session.putValue("username","111");
%>
<jsp:useBean id="workM" scope="page" class="test.faq" />
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<%!
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{
}
return "null";
}
%>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=760 align="center">
<TBODY>
<tr><td align="left" height=25><%if(session.getValue("username")!=null){out.println(session.getValue("username"));}%> 当前位置:<a href="../index.jsp">首页</a> -> 论坛 </td>
<%@ include file="date.inc"%>
</tr>
<TR bgColor=#3399ff>
<TD height=1 colspan="2"><IMG height=1 src="../images/spacer.gif"
width=16></TD></TR>
<tr><td height=10 colspan="2"><IMG height=1 src="../images/spacer.gif"
width=16></td></tr>
</TBODY></TABLE> <table align="center" border="0" width="760" cellspacing="0" cellpadding="0" height="355">
<tr>
<td width="150" height="355" valign="top">
<%@ include file="../table.inc"%>
</td>
<td width="10" height="100%"></td>
<td width="1" height="100%" bgcolor="#3399ff"></td>
<td width="10" height="100%"></td>
<td width="589" height="331" valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="images/bg1.gif">
<tr>
<td width="60%" height="20" bgcolor="#3399ff"> <font color="#ffffff">标题</font>
</td>
<td width="15%" height="20" bgcolor="#3399ff"> <font color="#ffffff">作者</font>
</td>
<td width="15%" height="20" bgcolor="#3399ff"> <font color="#ffffff">日期</font>
</td>
</tr>
<ul>
<%//算出共多少页
int t;
int mtotal;
t=0;
String strSQLsize="SELECT id FROM topic";
ResultSet RSsize = workM.executeQuery(strSQLsize);
while(RSsize.next()){
t=t+1;
}
//如果纪录总数除以每页的显示个数,余数大于0,那么
//逻辑页数应该为商+1
if((t%10)>0){
mtotal=t/10+1;
}else mtotal=t/10;
// out.println(mtotal);
%>
<%!String pageNo, mTmp;
int i, j, k;
%>
<%
pageNo = request.getParameter("pageNo");
//out.println(pageNo);=========null
if(pageNo == null){
pageNo = "1";
}
j = Integer.parseInt(pageNo);
// out.println(pageNo);=========1
// out.println(j);==========1
if(j < 1)
j = 1;
if(j > mtotal)
j = mtotal;
//out.println(j);
%>
<%
String strSQL="SELECT * FROM topic order by id desc";
ResultSet RSa = workM.executeQuery(strSQL);
for(k = 0;k < (j-1)*10;k++)
{
RSa.next();
} i = 0;
k = 1;
while (RSa.next()) {
//out.println("ok"+i+"ok");
i = i + 1;
//超过10条
if(i == 11)
{
k = 0;
break;
} out.print("<tr height='23'><td><li><a href=article.jsp?id="+RSa.getInt("id"));
out.print(">"+RSa.getString("title")+"</a></td><td>"+RSa.getString("author")+"</td><td>"+RSa.getDate("date")+"</td></tr>");
}
i = i - k;
//out.println("i de zhi::"+i);
RSa.close(); %>
<%//
if(j > 1)
{
%>
<a href="index.jsp?pageNo=1">第一页</a>
<%
int ii = Integer.parseInt(pageNo,10);
// out.println(ii);
if(ii > 1)
ii = ii -1;
String ssTmp = Integer.toString(ii);
%>
<a href="index.jsp?pageNo=<%=ssTmp%>">上一页</a>
<%
}
if(j < mtotal)
{
int ii = Integer.parseInt(pageNo,10);
if(ii < mtotal)
ii = ii + 1;
String ssTmp = Integer.toString(ii);
%>
<a href="index.jsp?pageNo=<%=ssTmp%>">下一页</a>
<a href="index.jsp?pageNo=<%=mtotal%>">最后页</a>
<%
}
if(mtotal < j)
j = mtotal;
%>
结果共<%=mtotal%>页,显示第<%=j%>页
<%////////////////////////////////////////////%>
<tr><td height="1" bgcolor="#3399ff" colspan="4"></td></tr>
<tr>
<td align="right" colspan="4" height="32"> <p align=right><a href="post.jsp">发表新言论</a>
</p>
</td><form name="form2" action="index.jsp" method="post">
<input type="hidden" name="pageNo" value="">
</form>
<script language="javascript">
function sub_page(id)
{
if(id==0)
document.form2.pageNo.value=0;
else if(id==1)
document.form2.pageNo.value=2;
document.form2.submit();
}
</script>
</tr>
</table>
</td>
</tr>
</table>
<%@ include file="../footer.inc"%>以下是header.inc文件:
<BODY bgColor=#ffffff leftMargin=0 topMargin=5 marginheight="5" marginwidth="5">
<table align="center" border="0" width="760" height="18" bgcolor="#3399FF" cellspacing="0">
<tr>
<td width="100%"><p>
<a class="x" href="member/index.jsp" target="_blank">注册区</a> |
<a class="x" href="study/index.jsp" target="_blank">学习区</a> |
<a class="x" href="forum/index.jsp" target="_blank">讨论区</a> |
<a class="x" href="exam/index.jsp" target="_blank">自测区</a>
</td>
</tr>
</table>
<HTML><HEAD><TITLE></TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<LINK href="css/site.css" rel=stylesheet>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<script language="javascript" src="../js/all.js">
</script>
<%@ include file="header.inc"%>
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="workM" scope="page" class="test.faq" />
<TABLE border=0 cellPadding=0 cellSpacing=0 width=760 align="center">
<TBODY>
<tr><td align="left" height=25>当前位置:<a href="index.jsp">首页</a> </td>
<%@ include file="date.inc"%>
</tr>
<TR bgColor=#3399ff>
<TD height=1 colspan="6"><IMG height=1 src="../../images/code.gif"
width=16></TD></TR>
<tr><td height=10 colspan="6"><IMG height=1 src="../../images/execute.gif"
width=16></td></tr>
</TBODY></TABLE>
<table align="center" border="0" width="760" cellspacing="0" cellpadding="0" height="355">
<tr>
<td width="150" height="355" valign="top">
<%@ include file="table.inc"%>
</td>
<td width="10" height="100%"></td>
<td width="1" height="100%" bgcolor="#3399ff"></td>
<td width="10" height="100%"></td>
<td width="589" height="331" valign="top" background="images/bg1.gif">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="307">
<tr>
<td width="100%" height="20" bgcolor="">
<a href="mailto:[email protected]">最新动态</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%@ include file="footer.inc"%>以下是讨论区的主页面文件:
<HTML><HEAD><TITLE></TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<LINK href="css/site.css" rel=stylesheet>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<script language="javascript" src="../js/all.js">
</script>
<%@ include file="header.inc"%>
<%@ page language="java" import="java.sql.*" %>
<%session.putValue("username","111");
%>
<jsp:useBean id="workM" scope="page" class="test.faq" />
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<%!
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{
}
return "null";
}
%>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=760 align="center">
<TBODY>
<tr><td align="left" height=25><%if(session.getValue("username")!=null){out.println(session.getValue("username"));}%> 当前位置:<a href="../index.jsp">首页</a> -> 论坛 </td>
<%@ include file="date.inc"%>
</tr>
<TR bgColor=#3399ff>
<TD height=1 colspan="2"><IMG height=1 src="../images/spacer.gif"
width=16></TD></TR>
<tr><td height=10 colspan="2"><IMG height=1 src="../images/spacer.gif"
width=16></td></tr>
</TBODY></TABLE> <table align="center" border="0" width="760" cellspacing="0" cellpadding="0" height="355">
<tr>
<td width="150" height="355" valign="top">
<%@ include file="../table.inc"%>
</td>
<td width="10" height="100%"></td>
<td width="1" height="100%" bgcolor="#3399ff"></td>
<td width="10" height="100%"></td>
<td width="589" height="331" valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="images/bg1.gif">
<tr>
<td width="60%" height="20" bgcolor="#3399ff"> <font color="#ffffff">标题</font>
</td>
<td width="15%" height="20" bgcolor="#3399ff"> <font color="#ffffff">作者</font>
</td>
<td width="15%" height="20" bgcolor="#3399ff"> <font color="#ffffff">日期</font>
</td>
</tr>
<ul>
<%//算出共多少页
int t;
int mtotal;
t=0;
String strSQLsize="SELECT id FROM topic";
ResultSet RSsize = workM.executeQuery(strSQLsize);
while(RSsize.next()){
t=t+1;
}
//如果纪录总数除以每页的显示个数,余数大于0,那么
//逻辑页数应该为商+1
if((t%10)>0){
mtotal=t/10+1;
}else mtotal=t/10;
// out.println(mtotal);
%>
<%!String pageNo, mTmp;
int i, j, k;
%>
<%
pageNo = request.getParameter("pageNo");
//out.println(pageNo);=========null
if(pageNo == null){
pageNo = "1";
}
j = Integer.parseInt(pageNo);
// out.println(pageNo);=========1
// out.println(j);==========1
if(j < 1)
j = 1;
if(j > mtotal)
j = mtotal;
//out.println(j);
%>
<%
String strSQL="SELECT * FROM topic order by id desc";
ResultSet RSa = workM.executeQuery(strSQL);
for(k = 0;k < (j-1)*10;k++)
{
RSa.next();
} i = 0;
k = 1;
while (RSa.next()) {
//out.println("ok"+i+"ok");
i = i + 1;
//超过10条
if(i == 11)
{
k = 0;
break;
} out.print("<tr height='23'><td><li><a href=article.jsp?id="+RSa.getInt("id"));
out.print(">"+RSa.getString("title")+"</a></td><td>"+RSa.getString("author")+"</td><td>"+RSa.getDate("date")+"</td></tr>");
}
i = i - k;
//out.println("i de zhi::"+i);
RSa.close(); %>
<%//
if(j > 1)
{
%>
<a href="index.jsp?pageNo=1">第一页</a>
<%
int ii = Integer.parseInt(pageNo,10);
// out.println(ii);
if(ii > 1)
ii = ii -1;
String ssTmp = Integer.toString(ii);
%>
<a href="index.jsp?pageNo=<%=ssTmp%>">上一页</a>
<%
}
if(j < mtotal)
{
int ii = Integer.parseInt(pageNo,10);
if(ii < mtotal)
ii = ii + 1;
String ssTmp = Integer.toString(ii);
%>
<a href="index.jsp?pageNo=<%=ssTmp%>">下一页</a>
<a href="index.jsp?pageNo=<%=mtotal%>">最后页</a>
<%
}
if(mtotal < j)
j = mtotal;
%>
结果共<%=mtotal%>页,显示第<%=j%>页
<%////////////////////////////////////////////%>
<tr><td height="1" bgcolor="#3399ff" colspan="4"></td></tr>
<tr>
<td align="right" colspan="4" height="32"> <p align=right><a href="post.jsp">发表新言论</a>
</p>
</td><form name="form2" action="index.jsp" method="post">
<input type="hidden" name="pageNo" value="">
</form>
<script language="javascript">
function sub_page(id)
{
if(id==0)
document.form2.pageNo.value=0;
else if(id==1)
document.form2.pageNo.value=2;
document.form2.submit();
}
</script>
</tr>
</table>
</td>
</tr>
</table>
<%@ include file="../footer.inc"%>以下是header.inc文件:
<BODY bgColor=#ffffff leftMargin=0 topMargin=5 marginheight="5" marginwidth="5">
<table align="center" border="0" width="760" height="18" bgcolor="#3399FF" cellspacing="0">
<tr>
<td width="100%"><p>
<a class="x" href="member/index.jsp" target="_blank">注册区</a> |
<a class="x" href="study/index.jsp" target="_blank">学习区</a> |
<a class="x" href="forum/index.jsp" target="_blank">讨论区</a> |
<a class="x" href="exam/index.jsp" target="_blank">自测区</a>
</td>
</tr>
</table>
IMPORTANT don't modify the generated servlets
HANDLER THREAD PROBLEM:java.net.SocketException:Socket is closed
at java.net.Socket.getInputStream (Socket.java:672)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)
你看看结果页面的代码有没有什么问题,再对应相应的JSP代码修改
还有,我觉得页面的<body></body>直接写在页面上,不要写在include的页面中比较好