我的jsp文件是:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@ page import="com.elc.util.*" %>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Select Your Department</h1>
<s:form action="Comapny">
<table bordercolor="red">
<tr>
<td>Select your Option</td>
<td>
<s:combobox name ="Depart"list="%{depat}" value="Select" headerValue="-1"
headerKey="select your option"></s:combobox>
</td>
</tr>
<tr>
<td></td>
<td>
<s:submit value="Select"></s:submit>
</td>
</tr>
</table>
</s:form>
</body>
</html>
A而我的动作课是...
package com.elc.action;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class Department extends ActionSupport {
private String Dept;
private List<Object> depat;
public List<Object> getDepat() {
return depat;
}
public void setDepat(List<Object> depat) {
this.depat = depat;
}
public String getDept() {
return Dept;
}
public void setDept(String dept) {
Dept = dept;
}
//@SuppressWarnings("unchecked")
public String Select(){
Collection<String> o = DBConnection.getConnection();
depat = new ArrayList<Object>();
Iterator<String> i = o.iterator();
while(i.hasNext()){
depat.add(i);
}
System.out.println("the list contains..........."+depat);
return "success";
}
//@SuppressWarnings("static-access")
public String execute(){
return SUCCESS;
}
}
我的 DAO 课程是.......
package com.elc.action;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
public class DBConnection {
public static Collection<String> getConnection(){
ArrayList<String> l = new ArrayList<String>();
try{
Class.forName(DBConstants.Driver);
Connection con = DriverManager.getConnection(DBConstants.url,
DBConstants.userName, DBConstants.password);
Statement st = con.createStatement();
String query = DBConstants.SELECT +"* from role";
ResultSet rs = st.executeQuery(query);
while(rs.next()){
rs.getInt(1);
String dept = rs.getString(2);
l.add(dept);
}
}catch(ClassNotFoundException c){
System.out.println("the classs u are asking not found");
c.printStackTrace();
}catch(SQLException s){
System.out.println("the sql exception is occured");
s.printStackTrace();
}
return l;
}
}
首先,我在我的 DBConnection.getconnection 方法中使用了 Object 的返回,它以 [HR,Tester,Software Engineer] 检索了我的表,但是当我用来在我的 Web 中下拉时,它们按原样出现......即 [HR,Tester , 软件工程师] 所以我希望输出为该测试人员的第一个 Hr 及以下以及该软件工程师的以下。当我在 DBConnection.getconnection 方法中使用 Collection 或 List 返回时,我得到了 jasper 异常..
有没有人告诉我答案。。。。。。