编程开发 > JSP > 文章内容

jsp工作总结(8)

2016-10-4编辑:sunny
文件下载: ****************************
<%@ page import="java.io.*"%><%String filename = "THELP.DOC";
String filepath = "f:\\";response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
java.io.FileInputStream fileInputStream =new java.io.FileInputStream(filepath + filename);
int i;while ((i=fileInputStream.read()) != -1) {out.write(i);}fileInputStream.close();out.close();%>
28分页显示及打印: ****************************
<%@ page  errorPage="errorPage.jsp" %>
<%@ page language="java" import="java.sql.*" import="java.io.*"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="beans.DBConBean"%>
<%@ page import="AppletBean.FindAppletBean"%>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page session="true"%>
<jsp:useBean id="mybean" class="beans.DBConBean" scope="session"/>
<jsp:useBean id="sqldata" class="AppletBean.FindAppletBean" scope="session"/>
<html><head><SCRIPT LANGUAGE=javascript>
<!--function setPrint(){WB.ExecWB(8,1);}function previewPrint(){
printshow.style.visibility="hidden";WB.ExecWB(7,1)}function Printit(){
printshow.style.visibility="hidden";WB.ExecWB(6,1)}function show(){
printshow.style.visibility="visible";}//--></SCRIPT>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body bgcolor="#EBF5FC" background="images/10.jpg">
<%int pages=1;int colnum=7;
//String sdriver="sun.jdbc.odbc.JdbcOdbcDriver";//String sconn="jdbc:odbc:ZCGL";
//String suser="user";//String spass="manager";//mybean.Initialization(sdriver,sconn,suser,spass);
String aaa=(String)session.getAttribute("pp");if(aaa!=null&&aaa!="")
{pages=new Integer(aaa).intValue();//out.print("开始非空:");out.print(pages);
}else{String pt=String.valueOf(pages);session.setAttribute("pp",pt);
//out.print("为空:");out.print(pages);
}int pagesize=4;ResultSet result=null;ResultSet rcount=null;
String sql=new String(sqldata.getsql().getBytes("ISO8859_1"));
String Resultcount=new String(sqldata.getrscount().getBytes("ISO8859_1"));
int count=0;if(pages>0){try{rcount=mybean.executeQuery(Resultcount);
}catch(Exception ex){out.print("mybean.executeQuery:"+ex.getMessage());}}
if(rcount.next())count=rcount.getInt("id");rcount.close();if(count>0){try{
result=mybean.executeQuery(sql);}catch(Exception ex)
{out.print("mybean.executeQuery:"+ex.getMessage());}
int n=(int)(count/pagesize);if(n*pagesize<count)n++;
int pag=1;String nowpage=request.getParameter("pages");
if((nowpage!=null)&&(nowpage!="")){
pag=new Integer(request.getParameter("pages")).intValue();if((pag>=1)&&(pag<=n))
{pages=pag;}else {String aa=(String)session.getAttribute("pp");pages=new Integer(aa).intValue();
//out.print("转向-为超出范围输出:");out.print(pages);}}int i;String str="";
for(i=1;i<=(pages-1)*pagesize;i++)result.next();int j=result.getMetaData().getColumnCount();
int yeshu=j/colnum+1;%><div align="center"><%out.print("记录总条数:");
out.print(count);out.print("当前条数:");out.print(i);out.print("总页数:");out.print(n);
out.print("当前页数:");out.print(pages); %></div><div align="center">
<table  height="68" width="80%" border="1"><%int q=1;int ll=1;for(int ys=1;ys<=yeshu;ys++)
{int hang=1;%><tr><% for(;q<=j&&hang<=colnum;++q,++hang){%>
<td align="center"><%=result.getMetaData().getColumnName(q)%>
 <div align="center"></div></td><%}%></tr><%--这里边执行查询n次 --%>
<%result=mybean.executeQuery(sql);for( i=1;i<=(pages-1)*pagesize;i++)result.next();%>
<% ;for(i=0;i<pagesize&&result.next();i++){int hs=1;int k=ll;%><tr>
<% for(;k<=j&&hs<=colnum;hs++,k++){%><td height="24"><%=result.getString(k)%></td>
<%}%></tr><%}%><%ll+=colnum;}%><%String ptt=String.valueOf(pages);
session.setAttribute("pp",ptt);%></table></div><div align="center">
<table  border="0" width="66%"><tr>
<td width="80%"> <form  name="form" action=AppleyDispResult.jsp method="get">
<%result.close();if(n>1){%><% for(i=1;i<=n;i++)
out.print("<a href=AppleyDispResult.jsp?pages="+i+">"+i+"&nbsp;</a>");}}
int m=pages-1;int z=(int)(count/pagesize);if(z*pagesize<count)z++;int b=pages+1;
if(b>z)b=z;out.print("<a href=AppleyDispResult.jsp?pages="+1+">首页&nbsp;</a>");
out.print("<a href=AppleyDispResult.jsp?pages="+m+">上一页&nbsp;</a>");
out.print("<a href=AppleyDispResult.jsp?pages="+b+">下一页&nbsp;</a>");
out.print("<a href=AppleyDispResult.jsp?pages="+z+"> 尾页&nbsp;&nbsp;</a>");%>
跳到第: <input type="text" name="pages"  size=2>页
<input name="submit" type="submit" value="submit"></form></td>
<td width="20%"><form name="form1" method="post" action="DataOut.jsp">
<input type="submit" name="Submit" value="数据导出"> </form></td></tr></table>
</div></body></html>
jsp工作总结(6)

热点推荐

登录注册
触屏版电脑版网站地图