When I'm Dispatching a JSP page through Servlet by the following code:
String[] UserList = ViewAllUserBasedOnRights(UserViewBy);
request.getRequestDispatcher("/test/TestGetParameterValues.jsp?UserList="+UserList+"") .forward(request, response);
And the JSP page shows "**[Ljava.lang.String;@8b3f2a**".
Details:
//View users based on user roles
public static String[] ViewAllUserBasedOnRights(String UserName) throws Exception{
String[] retVal = null;
Connection con=null;
try{
con= DatabaseConnectionManager.getDatabaseConnectionMan ager().getConnection(DatabaseConnectionManager.EAG RO_APP_DB);
con.setAutoCommit(false);
Statement stmt = (Statement) con.createStatement();
Statement stmt1 = (Statement) con.createStatement();
String SQLStringCount = "SELECT COUNTAS COUNT FROM MASTER_USER_DATA WHERE " +
" USER_NAME NOT IN(SELECT A.USER_NAME FROM USER_TO_ROLE_MAPPING A, MASTER_ROLE_DATA B WHERE "+
" A.ROLE_NAME = B.ROLE_NAME AND A.ROLE_IDENTIFIER = B.ROLE_IDENTIFIER AND "+
" B.ROLE_PRIORITY < (SELECT MIN(B.ROLE_PRIORITY) FROM "+
" USER_TO_ROLE_MAPPING A, MASTER_ROLE_DATA B WHERE "+
" A.ROLE_NAME = B.ROLE_NAME AND A.ROLE_IDENTIFIER = B.ROLE_IDENTIFIER AND "+
" A.USER_NAME = '"+UserName+"'))";
try(ResultSet rs = stmt.executeQuery(SQLStringCount)){
int count = -1;
while(rs.next()){
count = Integer.parseInt(rs.getString("COUNT"));
}
if(count > 0){
String SQLString = "SELECT USER_NAME FROM MASTER_USER_DATA WHERE "+
" USER_NAME NOT IN(SELECT A.USER_NAME FROM "+
" USER_TO_ROLE_MAPPING A, MASTER_ROLE_DATA B WHERE "+
" A.ROLE_NAME = B.ROLE_NAME AND A.ROLE_IDENTIFIER = B.ROLE_IDENTIFIER AND "+
" B.ROLE_PRIORITY < (SELECT MIN(B.ROLE_PRIORITY) FROM "+
" USER_TO_ROLE_MAPPING A, MASTER_ROLE_DATA B WHERE "+
" A.ROLE_NAME = B.ROLE_NAME AND A.ROLE_IDENTIFIER = B.ROLE_IDENTIFIER AND "+
" A.USER_NAME = '"+UserName+"') ORDER BY USER_NAME ASC)";
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;
}
Code of my JSP page:
<table style="border:1px solid black;bor
der-collapse:collapse;" width="100%">
<tr>
<th style="border:1px solid black;" align="center" width="15%">Serial no.</th>
<th style="border:1px solid black;" align="center" width="70%">User Name as email</th>
</tr>
<%
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>
<% } %>
</table>