借CSDN宝地发个贴,jon820416@hotmail.com请进来。
关于你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>
注意,我已经很久不写代码,难免手生,上面的参考代码应该有错误。