First, Java gets the parameters passed in the URL address
1 /** 2 * Gets a Map collection of parameter names and parameter values in the URL 3 * @param URL 4 * @return 5 */ 6 private map<string, String> ; Geturlpramnameandvalue (string url) {7 string regex= "(\\?| &+) (. +?) = ([^&]*) ";//Regular expression matching parameter name and parameter value 8 Pattern p = pattern.compile (regEx); 9 Matcher m = p.matcher (URL), Linkedhashmap is an ordered Map collection that iterates through the output in the order in which it was added map<string, string> param Map = new linkedhashmap<string, string> (), while (M.find ()) { String paramname = M.group (2);// Gets the parameter name of String Paramval=m.group (3);//Gets the argument value of Parammap.put (ParamName, paramval); }17 return Parammap;18 }
Second, get the URL address of the request
1 /** 2 * Gets the requested URL address 3 * @return 4 * /5 public String Getrequesturl () {6 HttpServletRequest Request = Servletactioncontext.getrequest (); 7//Request.getrequesturl () gets to the parameter part of the URL without a parameter url,request.getquerystring () to get the full URL with the parameter, you need to piece together the two parts 8 String URL = request.getrequesturl () + "?" +request.getquerystring (); 9 return url;10 }
Third, obtain the requested IP address
1 /**2 * Get the requested IP address 3 * @return4 */5 public String getrequestipaddress () {6 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 can be converted to the specified format date 3 * @param str 4 * @return Date 5 */ 6 public Static Boolean isValid Date (String str, string formater) {7 Boolean convertsuccess=true; 8 simpledateformat format = new Simpledateform at (Formater); 9 try { format.setlenient (false); Format.parse (str); catch (ParseException e) { // E.printstacktrace () //If throw java.text.ParseException or NullPointerException, the format is not Convertsuccess=false;16 } + return convertsuccess;18 }
Some tips for Java development