Show.jsp
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
String Id,TypeValue;
Id=request.getParameter("Id");
TypeValue=request.getParameter("Type");
odbcQuery="select * from MediaLib where ID="+Id;
odbcRs=odbcStmt.executeQuery(odbcQuery); byte[] Buffer=new byte[1024*10];
InputStream InData=null;
OutputStream outData=null;
int iSize;
if(odbcRs.next())
{
outData=response.getOutputStream();
InData=odbcRs.getBinaryStream("MediaFile");
response.setContentType(TypeValue);
while(true)
{
iSize=InData.read(Buffer);
if(iSize==-1)
{
break;
}
outData.write(Buffer,0,iSize);
}
outData.flush();
response.flushBuffer();
}
odbcRs.close();
%>
<%@ include file="/DataIni/DataClose.jsp"%>

解决方案 »

  1.   

    Browse.jsp
    <%@ page contentType="text/html; charset=gb2312"%>
    <%@ include file="/DataIni/DataOpen.jsp"%>
    <%@ include file="/ScriptLib/Init.jsp"%>
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
    </head><body>
    <%@ include file="/TemplateLib/Head.jsp"%>
    <br>
    <center>
    <table border="0" cellpadding="0" cellspacing="0" width="80%">
      <tr>
        <td width="10%" class="TdClass_Head">多媒体库</td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="80%">
      <tr>
    <%
    odbcQuery="select distinct Category from MediaLib";
    odbcRs=odbcStmt.executeQuery(odbcQuery);
    String Category;
    int iCount;
    iCount=0;
    while(odbcRs.next())
    {
    iCount++;
    Category=odbcRs.getString("Category");
    %>             
        <td width="20%" class="TdClass_1">
          <a href="Browse.jsp?Category=<%=Category%>" style="color: #800000; font-size: 9pt; font-family: 宋体"><%=Category%></a>
        </td>
    <%if(iCount%5==0){%></tr><tr><%}%>
    <%
    }
    odbcRs.close();
    %>
    </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="80%">
      <tr>
    <%
    int Page;
    String strPage;
    strPage=request.getParameter("Page");
    if(strPage==null)
    {
    Page=1;
    }
    else
    {
    Page=java.lang.Integer.parseInt(strPage);
    }
    Category=request.getParameter("Category");
    if(Category!=null)
    {
    odbcQuery="select * from MediaLib where Category='"+Category+"'";
    }
    else
    {
    odbcQuery="select * from MediaLib";
    }
    odbcRs_=odbcStmt_.executeQuery(odbcQuery);
    int RecordSum,PageSum,PageSize;
    RecordSum=0;
    PageSum=0;
    odbcRs_.last();
    RecordSum=odbcRs_.getRow();
    PageSize=10;
    PageSum=(RecordSum+PageSize-1)/PageSize;
    if(Page>PageSum){Page=PageSum;}
    if(PageSum>0)
    {
    odbcRs_.absolute((Page-1)*PageSize+1);
    iCount=0;
    String Id,Type,Re;
    while(iCount<PageSize&&!odbcRs_.isAfterLast())
    {
    iCount++;
    Id=odbcRs_.getString("ID");
    Type=odbcRs_.getString("Type");
    Re=odbcRs_.getString("Re");
    %>
        <td width="20%" class="TdClass_1">
    <%if(Type.equals("image/*")){%>
        <br><img src="/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>" width=80 height=80 title="<%=Re%>"><br>
    <%}else if(Type.equals("audio/*")){%>
    <br><a href="#" onclick="var hwnd=window.open('','','');hwnd.document.write('<BgSound src=\'/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>\'>');"><%=Re%></a><br>
    <%}else if(Type.equals("video/*")){%>
    <br><img dynsrc="/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>" width=80 height=80 title="<%=Re%>"><br>
    <%}else if(Type.equals("application/msword")){%>
    <br><a href="#" onclick="window.open('/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>','','')"><%=Re%></a><br>
    <%}else if(Type.equals("application/vnd.ms-excel")){%>
    <br><a href="#" onclick="window.open('/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>','','')"><%=Re%></a><br>
    <%}else if(Type.equals("application/*")){%>
    <br><a href="#" onclick="window.open('/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>','','')"><%=Re%></a><br>
    <%}else{%>
    <br><br>
    <%}%>
        </td>
    <%if(iCount%5==0){%></tr><tr><%}%>
    <%
    odbcRs_.next();
    }
    }
    odbcRs_.close();
    for(int iResult=0;iResult<5-iCount%5+1;iResult++)
    {
    %>
        <td width="20%" class="TdClass_1"><br><br></td>
    <%
    }
    %>
    </tr>    
    </table>            
    <table border="0" width="80%" class="SubPageClass">
      <tr>
        <td width="25%" class="TdClass_0"><%if(Page>1){%><a href="Browse.jsp?Category=<%=Category%>&Page=<%=Page-1%>">上一页</a><%}%></td>
        <td width="25%" class="TdClass_0">记录<%=RecordSum%>条</td>
        <td width="25%" class="TdClass_0">共有<%=PageSum%>页</td>
        <td width="25%" class="TdClass_0"><%if(Page<PageSum){%><a href="Browse.jsp?Category=<%=Category%>&Page=<%=Page+1%>">下一页</a><%}%></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="80%">
      <tr>
        <td width="100%" class="TdClass_Head"><input type="button" value="返回" id="Return" name="Return" onclick="window.location.href='/Index.jsp'"></td>
      </tr>
    </table>
    </form>
    </center>
    <%@ include file="/TemplateLib/Tail.jsp"%>
    <%@ include file="/DataIni/DataClose.jsp"%>
    </body></html>