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