打印實際值「request.getparameterValues」:不能在JSP
String[] UserList = ViewAllUserBasedOnRights(UserViewBy);
request.getRequestDispatcher("/test/TestGetParameterValues.jsp?UserList="+UserList+"").forward(request, response);
而JSP頁面顯示「[Ljava.lang。字符串; @ 8b3f2a「。
在這種方法「ViewAllUserBasedOnRights();
」值從我的數據庫是收集和其將返回NULL
或一組Strings
。
詳情:
我的JSP頁面,它很簡單的public static String[] ViewAllUserBasedOnRights(String UserName) throws Exception{
String[] retVal = null;
Connection con=null;
try{
con= DatabaseConnectionManager.getDatabaseConnectionManager().getConnection(DatabaseConnectionManager.EAGRO_APP_DB);
con.setAutoCommit(false);
Statement stmt = (Statement) con.createStatement();
Statement stmt1 = (Statement) con.createStatement();
String SQLStringCount = "....";
try(ResultSet rs = stmt.executeQuery(SQLStringCount)){
int count = -1;
while(rs.next()){
count = Integer.parseInt(rs.getString("COUNT"));
}
if(count > 0){
String SQLString =".....";
System.out.println("SQLString: "+SQLString);
try(ResultSet rs1 = stmt1.executeQuery(SQLString)){
ArrayList<String> stringList = new ArrayList<String>();
while(rs1.next()){
stringList.add(rs1.getString("USER_NAME"));
}
String[] temp = new String[stringList.size()];
retVal = (String[]) stringList.toArray(temp);
con.commit();
rs1.close();
}catch(SQLException e){
try{
if(con!=null)
extracted(con);
}catch(Exception ex){}
}
}
}catch(SQLException e){
try{
if(con!=null)
extracted(con);
}catch(Exception ex){}
}
}catch(SQLException e){
try{
if(con!=null)
extracted(con);
}catch(Exception ex){}
}
return retVal;
}
代碼只是我趕上值和打印:
<%
String[] UserList;
UserList = (String[])request.getParameterValues("UserList");
for(int i = 0; i < UserList.length; i++){
%>
<tr>
<td style="border:1px solid black;" align="center"><%=i+1%>
</td>
<td style="border:1px solid black;" align="left" ><%=UserList[i]%>
</td>
</tr>
<% } %>
建議接受有用的答案。 – 2013-04-05 07:41:56