当我通过以下代码通过 Servlet 调度 JSP 页面时:
String[] UserList = ViewAllUserBasedOnRights(UserViewBy);
request.getRequestDispatcher("/test/TestGetParameterValues.jsp?UserList="+UserList+"").forward(request, response);
JSP 页面显示“ [Ljava.lang.String;@8b3f2a ”。
在此方法中,“ ViewAllUserBasedOnRights();
”值是从我的数据库中收集的,它将返回一个NULL
或一组Strings
.
细节:
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;
}
我的 JSP 页面的代码,它非常简单,只需我捕获值并打印:
<%
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>
<% } %>