H
harryos
hi,
In an application I need to retrieve the ParameterMap from a servlet
request and use an iterator to go through the map entries and get the
key value pairs.I did it like this
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException{
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter( );
...
Map param_map=request.getParameterMap();
Iterator iterator = param_map.entrySet( ).iterator();
while(iterator.hasNext( )){
Map.Entry me = (Map.Entry)iterator.next( );
out.println(me.getKey( ) + ":>> ");
String[] arr = (String[]) (me.getValue( ));
for(int i=0;i<arr.length;i++){
out.println(arr);
if (i > 0 && i != arr.length-1)
out.println(", ");
}
out.println("<br><br>");
}
....
}
Though this code compiles without any errors,I think I need to use the
<K,V > notation to specify the types.I tried to do that as below.
Map<String,String[]> param_map=(Map<String,String[]>)
(request.getParameterMap());
I am getting a warning for unchecked cast.
warning: [unchecked] unchecked cast
[javac] found : java.util.Map
[javac] required: java.util.Map<java.lang.String,java.lang.String[] [javac] Map<String,String[]> param_map=(Map<String,String[]>)
(request.getParameterMap());
Can someone help me correct this ?
thanks
harry
In an application I need to retrieve the ParameterMap from a servlet
request and use an iterator to go through the map entries and get the
key value pairs.I did it like this
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException{
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter( );
...
Map param_map=request.getParameterMap();
Iterator iterator = param_map.entrySet( ).iterator();
while(iterator.hasNext( )){
Map.Entry me = (Map.Entry)iterator.next( );
out.println(me.getKey( ) + ":>> ");
String[] arr = (String[]) (me.getValue( ));
for(int i=0;i<arr.length;i++){
out.println(arr);
if (i > 0 && i != arr.length-1)
out.println(", ");
}
out.println("<br><br>");
}
....
}
Though this code compiles without any errors,I think I need to use the
<K,V > notation to specify the types.I tried to do that as below.
Map<String,String[]> param_map=(Map<String,String[]>)
(request.getParameterMap());
I am getting a warning for unchecked cast.
warning: [unchecked] unchecked cast
[javac] found : java.util.Map
[javac] required: java.util.Map<java.lang.String,java.lang.String[] [javac] Map<String,String[]> param_map=(Map<String,String[]>)
(request.getParameterMap());
Can someone help me correct this ?
thanks
harry