下面的代码,为什么我单步调试到client=new HttpClient(); 就直接finally ?package test;//验证手机号码信息import java.util.regex.Matcher;
import java.util.regex.Pattern;import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;public class MobileFromUtil {
//正则表达式,审核手机是否符合格式,可以只输入手机号码前7位
public static final String REGEX_IS_MOBILE=
"(?is)(^1[3|4|5|8][0-9]\\d{4,8}$)";
/**
* 获得手机号码信息
*
* @param mobileNumber
* @return
* @throws Exception
*/
public static String getMobileFrom(String mobileNumber) throws Exception {
if(!veriyMobile(mobileNumber)){
throw new Exception("不是完整的11位手机号或者正确的手机号前七位");
}
HttpClient client=null;
PostMethod method=null;
NameValuePair mobileParameter=null;
NameValuePair actionParameter=null;
int httpStatusCode=0;
String htmlSource=null;
String result=null;
try {
client=new HttpClient();
System.out.println("111");
/**
...
...
**/
} catch (RuntimeException e) {
e.printStackTrace();
}finally{
method.releaseConnection();
}
return result;
}
public static String parseMobileFrom(String htmlSource){
Pattern p=null;
Matcher m=null;
String result=null;
p=Pattern.compile(REGEX_GET_MOBILE);
m=p.matcher(htmlSource);
while(m.find()){
if(m.start(2)>0){
result=m.group(2);
result=result.replaceAll(" ", " ");
}
}
return result;
}
public static boolean veriyMobile(String mobileNumber){
Pattern p=null;
Matcher m=null;
p=Pattern.compile(REGEX_IS_MOBILE);
m=p.matcher(mobileNumber);
return m.matches();
} /**
* 测试
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
System.out.println(getMobileFrom("18699997777"));
}
}
import java.util.regex.Pattern;import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;public class MobileFromUtil {
//正则表达式,审核手机是否符合格式,可以只输入手机号码前7位
public static final String REGEX_IS_MOBILE=
"(?is)(^1[3|4|5|8][0-9]\\d{4,8}$)";
/**
* 获得手机号码信息
*
* @param mobileNumber
* @return
* @throws Exception
*/
public static String getMobileFrom(String mobileNumber) throws Exception {
if(!veriyMobile(mobileNumber)){
throw new Exception("不是完整的11位手机号或者正确的手机号前七位");
}
HttpClient client=null;
PostMethod method=null;
NameValuePair mobileParameter=null;
NameValuePair actionParameter=null;
int httpStatusCode=0;
String htmlSource=null;
String result=null;
try {
client=new HttpClient();
System.out.println("111");
/**
...
...
**/
} catch (RuntimeException e) {
e.printStackTrace();
}finally{
method.releaseConnection();
}
return result;
}
public static String parseMobileFrom(String htmlSource){
Pattern p=null;
Matcher m=null;
String result=null;
p=Pattern.compile(REGEX_GET_MOBILE);
m=p.matcher(htmlSource);
while(m.find()){
if(m.start(2)>0){
result=m.group(2);
result=result.replaceAll(" ", " ");
}
}
return result;
}
public static boolean veriyMobile(String mobileNumber){
Pattern p=null;
Matcher m=null;
p=Pattern.compile(REGEX_IS_MOBILE);
m=p.matcher(mobileNumber);
return m.matches();
} /**
* 测试
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
System.out.println(getMobileFrom("18699997777"));
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货