jsp图片上传首页如何显示上下页分页图片

shili21 发布于 2011/06/07 09:05
阅读 1K+
收藏 0
JSP

<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  </head>
  <script type="text/javascript">
  function sett(x){
  document.getElementById('a').value=x;
  }
  </script>
  <script type="text/javascript"src="datepicker.js"></script>
  <script type="text/javascript"src="ajax.js"></script>
  <script type="text/javascript">
   var ajax;
   var p=1;
   function getp(pageno,numperpage){
   ajax=creatAjax();
   ajax.omreadystatechange=sett;
   ajax.open("post","servlet/GetSomePhotos?pageno="pageno+"&numperpage="+numperpage,true);
   ajax.send(null);
   }
  function sett(){
  if(ajax.readyState==4){
   if(ajax.status==200){
   var s=ajax.responseXML;
   var i;
   for(i=0;i<s.getElementsByTagName("photo").length;i++){
   var t="";
   t="<img width=100 height=100 src='photo/"s.getElementByTagName("filename")[i].childNodes[0].nodeValue+"'>";
   t=t+"<br>"+s.getElementByTagName("filename")[i].childNodes[0].nodeValue;
   document.getElementById("td"+i).innerHTML=t;
   }
   for(;i<5;i++){
   document.getElementById("td"+i.innerHTML="";
   }
   }
  }
  }
  getp(p,5);
  function setpage(x){
  p=p+x;
  if(p==0){
  p=1;
  }else{
  getp(p,5);
  }
  }
  </script>
 
 
 <%File f= new File(request.getRealPath("photos"));
   File fs[]=f.listFiles();
  for(int i=0;i<fs.length;i++){
  if(fs[i].getName().endsWith(".jpg"))
   %>
   <a href="javascript:sett('<%=fs[i].getName() %>')"><img src='photos/<%=fs[i].getName() %>' width=80 height=80></a>
   <%} %>
 <a href="up.jsp" target="_blank">上传图片</a>
 <form action="servlet/UploadFile" medthod="post">
   <input type="text" name="a"><br>
 <input type="text" name="u"><br>
 <input name=txt onfocus="setday(this,document.all.txt)"><br>
 <input type="submit" value="保存">

 </form> 
<body >
  <table width="587" height="43">
  <tr><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td></tr><tr>
  <td id="td0"></td>
  <td id="td1"></td>
  <td id="td2"></td>
  <td id="td3"></td>
  <td id="td4"></td>

  </tr>
  </table>
  <a href="javascript:setpage(-1)">上一页</a>
  <a href="javascript:setpage(1)">下一页</a>
 </body>
</html>

加载中
返回顶部
顶部