借CSDN宝地发个贴,jon820416@hotmail.com请进来。

Leemaasn 2004-02-18 02:39:37
关于你2004年2月18日上午问我的问题,我把它整理了一下,贴在下面,你自己看看,有什么问题你再跟贴,我不一定知道,也许别人知道。嘿。
1、下面这个类来自Struts



package org.apache.struts.util;


import java.io.Serializable;




public class LabelValueBean implements Serializable {



public LabelValueBean(String label, String value) {
this.label = label;
this.value = value;
}



private String label;

public String getLabel() {
return this.label;
}

public void setLabel(String label) {
this.label = label;
}



private String value;

public String getValue() {
return this.value;
}

public void setValue(String value) {
this.value = value;
}



public String toString() {
StringBuffer sb = new StringBuffer("LabelValueBean[");
sb.append(this.label);
sb.append(", ");
sb.append(this.value);
sb.append("]");
return (sb.toString());
}


}


2、在你的DBuse.java里
public String[] getFilePath(String id) throws SQLException{
String[] filePath = null; //DButil db = new DButil();
Connection conn = getConnection();
if (id == null) {
System.out.println("Please give parameter id!");
//return;
}
String sql = "select daPath from datainfo where workID="+id;
setstrSql(sql);
Vector vector = getVectorResult();
//注意,下面是我增加的,仅供参考
ResultSet rs = Statement.execute(sql);
//每一个记录假设包含两个字段:Label,Value
Vector v = new Vector ();
while(rs.next())
{
LabelValueBean bean = new LabelValueBean (rs.getString (1), rs.getString(2));
v.add (bean);
}
request.setAttribute("result", v);
//注意,上面是我增加的,仅供参考
return filePath;
}


3、在你的Jsp里

<%
Vector v = (Vector)request.getAttribute ("result");
while(v.hasNext()){
LabelValueBean bean = (LabelValueBean)v.getFirstElemetn();
%>
<td align="center"><a href="Javascript ownloadFile('<%=bean.getLabel()%>','<%=bean.getValue()%>');"><img border="0" src="../../images/rar.gif" width="16" height="16"></a></td>


注意,我已经很久不写代码,难免手生,上面的参考代码应该有错误。
...全文
45 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧