newxy技术零java代码实现文件下载,下载记数 作者:胡立新

来源:互联网 发布:怎么样申请淘宝店铺 编辑:程序博客网 时间:2024/04/30 12:19

假设session中有一名为fileBean的java bean,其中有一属性title是资源名,资源名最好有文件类型后缀,一属性content是文件内容。 设数据库中有一表downCount用于下载记数,有一主关键字,为数据类型如整型,或字符串型,另有一字段保存下载的资源名,这字段为 resName varchar(255) not null,而且必须要有名为resName这个字段。

在web.xml中申明net.newxy.servlet.Download。

  <servlet>
    <servlet-name>download</servlet-name>
    <servlet-class>net.newxy.servlet.Download</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>download</servlet-name>
    <url-pattern>/download</url-pattern>
  </servlet-mapping>

建立下载链接:<html:link target="_blank" page="/download?table=downCount&name=fileBean&property=content&fileName=title">下载</html:link>

可以参看范例 http://www.newxy.net/zh_cn/samples/index.jsp

newxy(新座标)技术网站 http://www.newxy.net

显示下载记数:

<nbean:formBean name="downCounts" refresh="true" sql="select resName,count(*) as counts from downCount group by resName order by resName"/>
<logic:notEmpty name="downCounts" property="_coll">
  <table border="1">
    <caption>下载计数</caption>
    <tr>
      <td>资源名</td><td>下载次数</td>
    </tr>
    <logic:iterate id="rec" name="downCounts" property="_coll">
      <tr>
        <td><bean:write name="rec" property="resName"/></td>
        <td align="center"><bean:write name="rec" property="counts" /></td>
      </tr>
    </logic:iterate>
  </table>
</logic:notEmpty>

原创粉丝点击