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

📄 viewinfo1.jsp

📁 此资源是jsp应用开发 邓子云等编写的一书里的源代码
💻 JSP
字号:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*,javax.naming.*,javax.sql.DataSource" %>
<html>
  <body bgcolor="#DCDADA">
  当前位置:信息中心-->查看信息<br>
  <%int pageSize=10;//每页显示的记录条数
  	int allRecordCount=0;//记录总条数
  	int pageRecordCount=0;//当前页记录条数
  	int pageCount=0;//总页数
  	int diPage=1;//当前页码
  	//------接收请求参数------  	
  	try{
  		diPage=Integer.parseInt(request.getParameter("diPage"));
  	}catch(Exception e){
  		diPage=1;
  	}
  %>
  <%//------构造查询的SQL语句------
  	//sqlStr1为查询到当前页数据的SQL语句
  	//sqlStr2为查询到总记录条数的SQL语句
  	String sqlStr1="select top "+diPage*pageSize+" * from info where "+
  		"infoId not in (select top "+(diPage-1)*pageSize+" infoId from"+
  		" info order by infoId desc) order by infoId desc"; 		
  	String sqlStr2="select count(*) as allCount from info";
  %>
  <%//------得到数据库连接------
  	Context initCtx = new InitialContext(); 
	Context ctx = (Context) initCtx.lookup("java:comp/env");
	Object obj = (Object) ctx.lookup("jdbc/sqlserver");
	DataSource ds = (javax.sql.DataSource)obj;
	Connection conn = ds.getConnection();
  %>
  <%//------得到总页数、总记录条数与当前页记录条数------
  	java.sql.Statement sql1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  	java.sql.ResultSet rs1=null;
  	rs1=sql1.executeQuery(sqlStr2);
  	if(rs1!=null){
  		//---得到总页数、总记录条数与当前页记录条数---
  		rs1.next();
  		allRecordCount=rs1.getInt("allCount");
  		if(allRecordCount%pageSize==0)
  			pageCount=allRecordCount/pageSize;
  		else
  			pageCount=(int)(allRecordCount/pageSize)+1;
  		if(diPage==pageCount||pageCount==0)//最后一页或没有数据
  			pageRecordCount=allRecordCount-(diPage-1)*pageSize;
  		else
  			pageRecordCount=pageSize;
  	}
  %>
  <table border="1" CELLSPACING=0 CELLPADDING=0>
  	<tr><td colspan="3" align="center">
  		查看信息(共<%=allRecordCount%>条,当前页<%=pageRecordCount%>条)
  		&nbsp;&nbsp;&nbsp;&nbsp;
  		<%if(diPage!=1){//不是第一页
  			out.print("<a href='viewInfo1.jsp?diPage=1'>首页</a>&nbsp;");
  			out.print("<a href='viewInfo1.jsp?diPage="+(diPage-1)+"'>上一页</a>&nbsp;");
  		  }
  		  if(diPage!=pageCount&&pageCount!=0){//不是最后一页
  			out.print("<a href='viewInfo1.jsp?diPage="+(diPage+1)+"'>下一页</a>&nbsp;");
  			out.print("<a href='viewInfo1.jsp?diPage="+pageCount+"'>尾页</a>&nbsp;");
  		  }
  		%>
  	</td>
  	</tr>
  	<tr><td>信息标题</td><td>查看?</td>
  	<%if(session.getAttribute("departmentId")!=null){
  		if(Integer.parseInt(session.getAttribute("departmentId").toString())==1){%>
  		<td>删除?</td>
  	<%	}
  	  }
  	%>
  	</tr>
  	<%//------得到当前面数据并显示------
  	java.sql.ResultSet rs2=null;
  	java.sql.Statement sql2=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  	rs2=sql2.executeQuery(sqlStr1);
  	if(rs2!=null){
  		while(rs2.next()){%>
  	<tr><td>[<%=rs2.getString("infoAddTime").substring(0,10)%>]<%=rs2.getString("infoTitle")%></td>
  		<td><a href="#" onclick="window.open('viewInfo2.jsp?infoId=<%=rs2.getLong("infoId")%>')">查看</a></td>
  	<%if(session.getAttribute("departmentId")!=null){
  		if(Integer.parseInt(session.getAttribute("departmentId").toString())==1){%>
  		<td><a href="delInfo.jsp?infoId=<%=rs2.getLong("infoId")%>">删除</a></td>
  	<%	}
  	  }
  	%>
  	</tr>	
  	<%
  		}
  	 }%>
  	<%
  	  if(conn!=null)
  		conn.close();
  	%>
  </table>
  </body>
</html>

⌨️ 快捷键说明

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