⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 category.jsp

📁 jsp的技术教程
💻 JSP
字号:
<%@ include file="head.inc"%>
	<%@ page language="java" import="java.sql.*" %>
	<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";
}
%>   
<%@ include file="function.inc.jsp"%>                      
<TABLE border=0 cellPadding=0 cellSpacing=0 width=760 align="center">
  <TBODY>
  <tr><td align="left" height=25><%if(session.getAttribute("username")!=null){out.println(session.getAttribute("username"));}%>  当前位置:<a href="../index.jsp">首页</a> -&gt; <a href="all_category.jsp">商品分类</a> 
  <%
  String dirname;
  Integer dir=new Integer(request.getParameter("id"));
  switch(dir.intValue())
  {
  		case 1:
			dirname="计算机类  ";
			break;
		case 2:
			dirname=" 英语类  ";
			break;
		default:
			dirname=" 其他类  ";
			break;
  }
  %>
 -&gt;  <%=dirname%>
    </td>
 <%@ include file="../member/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">                  
					               
	                
		</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">                  
          <tr>                  
            <td width="62%" height="20" bgcolor="#3399ff">&nbsp;<font color="#ffffff">标题</font>       
			</td>
            <td width="15%" height="20" bgcolor="#3399ff">&nbsp;<font color="#ffffff">作者</font>       
			</td>
            <td width="15%" height="20" bgcolor="#3399ff">&nbsp;<font color="#ffffff">类别</font>       
			</td>
            <td width="8%" height="20" bgcolor="#3399ff">&nbsp;<font color="#ffffff"></font>       
			</td>
		  </tr>
		  <ul>
	

	<%///////////////算出共多少页
		int t;
		int mtotal;
		t=0;
		String cate;
		cate=request.getParameter("id");

		String strSQLsize="SELECT id FROM book where category="+cate;
	//	out.println(strSQLsize);
		ResultSet RSsize = workM.executeQuery(strSQLsize);
	//	out.print(RSsize.next());
		while(RSsize.next()){
			t=t+1;
		//	out.println(t);
		}

		//out.println(t%3>0);
		//如果纪录总数除以每页的显示个数,余数大于0,那么
		//逻辑页数应该为商+1
		if((t%3)>0){
			mtotal=t/3+1;
		}else mtotal=t/3;
	//	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 book where category="+cate+" order by id desc";
		ResultSet RSa = workM.executeQuery(strSQL);
		
		for(k = 0;k < (j-1)*3;k++)
		{	//out.println(RSa.next());

			RSa.next();
		}

		i = 0;
		k = 1;
		while (RSa.next()) {
			//out.println("ok"+i+"ok");
			i = i + 1;
		    //超过3条
		    if(i == 4)
		    {
		        k = 0;
		        break;
		    }     

				out.print("<tr height='23'><td><li><a href=book.jsp?id="+RSa.getInt("id"));
				out.print(">"+getStr(RSa.getString("name"))+"</a></td><td>"+getStr(RSa.getString("author"))+"</td><td>"+category(RSa.getInt("category"))+"</td><td></td></tr>");
			
			}
			i = i - k;
		//out.println("i de zhi::"+i);
		RSa.close();

	%>
<%////////////////////////////////////////////////
	if(j > 1)
{
%>
    <a href="category.jsp?id=<%=cate%>&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="category.jsp?id=<%=cate%>&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="category.jsp?id=<%=cate%>&pageNo=<%=ssTmp%>">下一页</a>
    <a href="category.jsp?id=<%=cate%>&pageNo=<%=mtotal%>">最后页</a>
<%
}
if(mtotal < j)
    j = mtotal;        
%>

<%////////////////////////////////////////////%>

		  <tr><td height="1" bgcolor="" colspan="2">
		  <hr color="#3399ff">
		  结果共<%=mtotal%>页,显示第<%=j%>页</td>
		  
			<td align="left" colspan="2" height="32">
			<a href="post.jsp">发布书的信息</a>
			</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>                  


	商品分类:<a href="category.jsp?id=1">计算机类</a> |
    		<a href="category.jsp?id=2">英语类 </a> |
			<a href="category.jsp?id=3">其他类 </a> |

        </td>
		
    </tr>
	
  </table>
<%@ include file="footer.inc"%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -