About type conversions and data acquisition for REQUEST.GETPARAMETERMAP ()

Source: Internet
Author: User

First, the PO on a self-written conversion class.

1 /**2      * @authorXfiler3 * @described Tool method for converting Request.getparametermap () to normal map4      * @paramRequest5      * @return6      */7      PublicMap<string, string>Convertmap (HttpServletRequest request) {8map<string, string> returnmap =NewHashmap<>();9         //Convert to EntryTenset<map.entry<string, string[]>> entries =Request.getparametermap (). EntrySet (); One         //Traverse A          for(Map.entry<string, string[]>entry:entries) { -String key =Entry.getkey (); -StringBuffer value =NewStringBuffer (""); theString[] val =Entry.getvalue (); -             if(NULL! = Val && val.length > 0) { -                  for(String v:val) { - Value.append (v); +                 } -             } + returnmap.put (Key, value.tostring ()); A         } at  -         returnReturnmap; -}

And then we're going to ask why did we do it?

Let's put an error message:

java.lang.ClassCastException: [Ljava.lang.String; cannot is cast to java.lang.String    at Com.xfiler.servlet.MyServlet.doGet (Myservlet.java:+)    

This error message indicates that the map returned by Request.getparametermap () is not our usual map<object,object> type, but Map<string,string[]> You need to convert the value part.

So back to the beginning of the code can be seen, did this part of the conversion.

About type conversions and data acquisition for REQUEST.GETPARAMETERMAP ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.