Some tips for Java development

Source: Internet
Author: User

Original: http://www.cnblogs.com/xdp-gacl/p/3490276.html

First, Java gets the parameters passed in the URL address

/*** Get the Map collection of parameter names and values in the URL *@paramURL *@return     */    PrivateMap<string, string>geturlpramnameandvalue (string url) {string regEx="(\\?| &+) (. +?) = ([^&]*) ";//regular expressions that match parameter names and parameter valuesPattern p =Pattern.compile (regEx); Matcher m=p.matcher (URL); //Linkedhashmap is an ordered map collection that iterates through the output in the order in which they are addedmap<string, string> parammap =NewLinkedhashmap<string, string>();  while(M.find ()) {String paramname= M.group (2);//Get parameter nameString Paramval=m.group (3);//Get parameter valuesparammap.put (paramname, paramval); }        returnParammap; }

Second, get the URL address of the request

/**      * Gets the URL address     of the request @return     *      /Public String Getrequesturl () {          = servletactioncontext.getrequest ();  ///  Request.getrequesturl () gets to the parameter part of the URL, url,request.getquerystring () without parameters, To get the full URL with parameters, you need to put the two pieces together.    String url = request.getrequesturl () + "?" +request.getquerystring ();     return URL;            }

Third, obtain the requested IP address

/**      * Gets the requested IP address      @return     */public      String getrequestipaddress () {        return  servletactioncontext.getrequest (). GETREMOTEADDR ();    }

Four: Determines whether a string can be converted to a date in the specified format

/*** Verify that the string can be converted to a date in the specified format *@paramSTR *@returnDate*/     Public Static Booleanisvaliddate (String str, string formater) {Booleanconvertsuccess=true; SimpleDateFormat format=NewSimpleDateFormat (Formater); Try{format.setlenient (false);       Format.parse (str); } Catch(ParseException e) {//E.printstacktrace (); //if throw java.text.ParseException or nullpointerexception, it means the format is not correct.convertsuccess=false; }        returnconvertsuccess; }

Some tips for Java development

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.