First, Java gets the parameters passed in the URL address
1/**2* Gets the map collection of parameter names and parameters values in the URL3*@paramUrl4*@return5*/6Private Map<string, string>Geturlpramnameandvalue (String URL) {7 String regex= "(\\?| &+) (. +?) = ([^&]*) ";//Regular expressions that match parameter names and parameter values8 Pattern p =Pattern.compile (REGEX);9 Matcher m =P.matcher (URL);10//Linkedhashmap is an ordered map collection that iterates through the output in the order in which they are added11 map<string, string> parammap = new linkedhashmap<string, String> () while (M.find ()) {13 String paramname = M.group (2); //14 String Paramval=m.group (3); // get parameter value 15 Parammap.put (paramname, paramval); 16 }17 return Parammap;
Second, get the URL address of the request
1/**2* Get the requested URL address3*@return 4 * /5 public String Getrequesturl () { 6 httpservletrequest request = Servletactio Ncontext.getrequest (); 7 // Request.getrequesturl () gets to the parameter part of the URL without the parameter url,request.getquerystring (), to get the full URL with the parameter, You need to put these two pieces together. 8 String url = request.getrequesturl () + "?" +request.getquerystring (); 9 return URL; Ten one }
Third, obtain the requested IP address
1 /** * Gets the requested IP address @return* /public String getrequestipaddress () {return Servletactioncontext.getrequest (). GETREMOTEADDR (); 7}
Four: Determines whether a string can be converted to a date in the specified format
1/**2* Verify that the string is converted to a date in the specified format3*@paramStr4*@returnDate5*/6PublicStaticBooleanIsvaliddate (String str, string formater) {7Boolean convertsuccess=True;8 SimpleDateFormat format =NewSimpleDateFormat (Formater);9Try{Ten Format.setlenient (False); 11 Format.parse (str); catch (ParseException e) { 13 //14 // if the throw Java.text.ParseException or nullpointerexception, it means that the format is not 15 Convertsuccess=false; 17 return convertsuccess; 18}
Some tips in Java development