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

📄 index.jsp~144~

📁 使用J2EE实现了软件园的下载和上传功能
💻 JSP~144~
字号:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.io.*,java.util.*,javax.naming.*,javax.rmi.*"%>
<%@include file="top.jsp"%>
<%!
 public String codeString(String s) {
    String str = s;
    try {
      byte b[] = str.getBytes("ISO-8859-1");
      str = new String(b);
      return str;
    }
    catch (Exception e) {
      return "error";
    }
  }
%>

<html>
<head>
<title>FileDownload</title>
<LINK href="css.css" type="text/css" rel="stylesheet">
</head>
<body>
<center>
  <table width="750">
    <tr>
      <td>
        <table width="200">
          <tr>
            <td>
              <table>
                <tr>
                  <td>
                    <img alt="" src="images/search.jpg"/>
                  </td>
                </tr>
                <tr>
                  <td>
                    <form method="GET" name=form action="searchResult.jsp">
                    <table>
                      <tr>
                        <td width="50%">
                          <input type=text name=keyword size="12" >
                        </td>
                        <td width="50%">
                          <input type=submit name=Submit value=搜索>
                        </td>
                      </tr>
                    </table>
                    </form>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td>
              <table>
                <tr>
                  <td>
                    <img alt="" src="images/softInfor.jpg"/>
                  </td>
                </tr>
                  <%
                    int i = 0; //i:总个数
                    try {
                      Context ic = new InitialContext();
                      Object obj = ic.lookup("softwareRemote");
                      software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                      Collection c = home.findAll();
                      Collection c2 = home.getTypes();
                      Iterator i2 = c2.iterator();
                      String strType = "";
                      while (i2.hasNext()) {
                        strType = i2.next().toString();
                        Collection c3 = home.getTypeSoftwares(strType);
                        %>
                        <tr>
                        <td><%=codeString(strType)%>:<font color="red"><%=c3.size()%></font>个</td>
                        </tr>
                        <%
                      }
                      i = c.size();
                    }
                    catch (Exception ex) {
                      ex.printStackTrace();
                    }
                  %>
                  <tr>
                  <td>
                    总共有<font color="red"><%=i%></font>个资源
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td>
              <table>
                <tr>
                  <td colspan="2">
                    <img alt="" src="images/downRange.jpg"/>
                  </td>
                </tr>
               <%
try{
   Context ic = new InitialContext();
   Object obj = ic.lookup("softwareRemote");
   software.softwareRemoteHome home = (software.softwareRemoteHome)PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
   Collection cr=home.getTop3();
   System.out.println("cr.size()"+cr.size());
   Iterator ir=cr.iterator();
   while(ir.hasNext()){
     software.softwareRemote sr=(software.softwareRemote)ir.next();
     String str=new String(sr.getSoftwareName().getBytes("iso8859-1"),"gb2312");
     int ir2=sr.getSoftwareDownloadTime().intValue();%>
     <tr>
     <td>
     <a href=software.jsp?softwareName=<%=str%>><%=str%></a>
     </td>
     <td>下载<font color="red"><%=ir2%></font>次</td>
     </tr>
     <%
   }
}catch(Exception ex){
ex.printStackTrace();}
%>
              </table>
            </td>
          </tr>
        </table>
      </td>
      <td>
        <table>
          <tr>
            <td>
              <img alt="" src="images/right.jpg"/>
            </td>
          </tr>
        <%
          try {
            javax.naming.Context ic = new javax.naming.InitialContext();
            Object obj = ic.lookup("softwareRemote");
            software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
            java.util.Collection c = home.findAll();
            //java.util.Iterator i=c.iterator();
            Object o[] = c.toArray();
            //System.out.println("c.size()"+c.size());
            // System.out.println("o.length"+o.length);
            if (o.length >= 5) {
              //int k=c.size()-4;
              for (int j = o.length - 5; j <= o.length - 1; j++) {
                //software.softwareRemote s=(software.softwareRemote)i.next();
                software.softwareRemote s = (software.softwareRemote) o[j];
        %>
          <tr>
            <td>
              <a href=class.jsp?classType=<%=new String(s.getSoftwareType().toString().getBytes("iso8859-1"),"gb2312")%>>[<%=new String(s.getSoftwareType().toString().getBytes("iso8859-1"),"gb2312")%>]</a>
              <a href=software.jsp?softwareName=<%=new String(s.getSoftwareName().toString().getBytes("iso8859-1"),"gb2312")%>><%=new String(s.getSoftwareName().toString().getBytes("iso8859-1"),"gb2312")%></a>
              &nbsp;&nbsp;&nbsp;&nbsp;<%=s.getSoftwareID().substring(0,7) %>
            </td>
          </tr>
        <%
          }} else {
            for (int j = 0; j <= o.length - 1; j++) {
              software.softwareRemote s = (software.softwareRemote) o[j];
        %>
          <tr>
            <td>
              <a href=class.jsp?classType=><%=new String(s.getSoftwareType().toString().getBytes("iso8859-1"),"gb2312")%>              </a>
              <a href=software.jsp?softwareName=><%=new String(s.getSoftwareName().toString().getBytes("iso8859-1"),"gb2312")%>              </a>
            </td>
          </tr>
        <%
          }
          }
              Collection c2 = home.getTypes();
          //System.out.println("TypeSize"+c2.size());
          Iterator i2 = c2.iterator();
          String strType = "", strSoftware;
          while (i2.hasNext()) {
            strType = i2.next().toString();
        %>
          <tr>
            <td style="background-image:url('images/soft2.jpg');height='30';width='400';" >              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <a href=class.jsp?classType=<%=new String(strType.getBytes("iso8859-1"),"gb2312")%>><%=new String(strType.getBytes("iso8859-1"),"gb2312")%>
              </a>
            </td>
          </tr>
        <%
          Collection c3 = home.getTypeSoftwares(strType);
          Iterator i3 = c3.iterator();
          while (i3.hasNext()) {
            strSoftware = i3.next().toString();
        %>
          <tr>
            <td>
              <a href="software.jsp?softwareName=<%=new String(strSoftware.getBytes("iso8859-1"),"gb2312")%>"><%=new String(strSoftware.getBytes("iso8859-1"),"gb2312")%></a>
            </td>
          </tr>
        <%
          }
          }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        %>
        </table>
      </td>
    </tr>
  </table>
</center>
</body>
</html>
<%@include file="foot.jsp"%>
<%--
  <%
  try {
  String dirStr = "E:/Download";
  File dir = new File(dirStr);
  File file[] = dir.listFiles();
  out.print("<h2>请选择下载的文件:</h2><br>");
  for (int i = 0; i < file.length; i++) {
  if (file[i].isFile()) {
  String filename = file[i].getName();
  %>
  &nbsp;&nbsp;
  <a href="downloadAction.jsp?filename=<%=filename%>"><%=filename%>              </a>
  <br>
  <%
  }
  }
  } catch (IOException e) {
  out.print("IOError!");
  }
  %>
--%>

⌨️ 快捷键说明

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