|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于一个大型项目,如果用java来作,可能需要9个月,并且可能需要翻阅10本以上的书,但如果用ruby来作,3个月,3本书就足够了,而.net也不过3,4本书足以,这就是区别。js|函数初学JSP时,写了一些工具函数由于不太会用JAVA下的正则表达式也只能这么写啦!收回来让人人品评品评提点定见!有几个函数不算是本人写的但愿爱挑剌的伴侣嘴下包涵!我是老手我怕谁,脸皮不可的人程度也上不往呀.嘻嘻..
packagemxzc.web.strctrl;
publicclassStringCtrl
{/********************************************
publicsynchronizedStringHTMLcode(StringTXTcode)功效:文本交换
publicsynchronizedStringUnhtmlcode(Stringstr)功效:(不完整)反文本交换
publicsynchronizedStringUnhtmlcodea(Stringstr)功效:反文本交换
publicsynchronizedbooleanemailcheck(Stringemail)功效:反省一个字符串是不是切合E-Mail
publicsynchronizedbooleanisemailstr(Stringemail)功效:反省一个字符串是不是切合E-Mail
publicsynchronizedbooleanisqqstr(Stringqq)功效:反省一个字符串是不是切合QQ
publicsynchronizedbooleanisnumstr(Stringnum)功效:反省一个字符串是不是为一数字串
publicsynchronizedStringuserstrlow(Stringuser)功效:交换用户名中分歧法的部分
publicsynchronizedbooleanuserstrchk(Stringuser)功效:反省字符串是不是切合用户名法例
publicsynchronizedbooleanistelstr(Stringtel)功效:反省字符串是不是为TEL
publicsynchronizedbooleanurlcheck(Stringurl)功效:反省字符串是不是为URL
publicsynchronizedStringisotogbk(Stringiso)功效:ISO9006-1码转换为GBK
publicsynchronizedStringgbktoiso(Stringgbk)功效:GBK码转换为ISO9006-1
publicsynchronizedStringdostrcut(Stringoldstr,intlength)功效:按汉字长换行(英文按半个字长)
publicsynchronizedStringinttodateshow(intdatenum)功效:将1900年至工夫的秒数换为日期字符串
publicsynchronizedStringnowdateshow()功效:显现以后日期
publicsynchronizedjava.util.Dateinttodate(intdatenum)功效:将秒数转换为日期
publicsynchronizedintdatetoint()功效:将工夫换为从1900年至今的秒数
publicsynchronizedintdatetoint(java.util.Dated)功效:将工夫换为从1900年至工夫的秒数
publicsynchronizedStringoverlengthcut(Stringstr,intlength)功效:截取前几个字符,单元为汉字字长
publicsynchronizedStringreplace(Stringstr,Stringsuba,Stringsubb)功效:字符串交换
*********************************************/
privatestaticfinalStringisostr="ISO8859-1";
privatestaticfinalStringgbkstr="GBK";
publicStringCtrl()
{
}
publicsynchronizedbooleanemailcheck(Stringemail)
{
if(email==null)returnfalse;
if(email.length()<6)returnfalse;
if(email.indexOf("@")<2)returnfalse;
if(email.indexOf(".")<4)returnfalse;
if(email.endsWith(".")||email.endsWith("@"))returnfalse;
if(email.lastIndexOf("@")>email.lastIndexOf(".")-1)returnfalse;
if(email.lastIndexOf("@")!=email.indexOf("@"))returnfalse;
String[]lowstr={"",""","
","&"," ","","<",">","/","","#"};
for(inti=0;i<lowstr.length;i++)if(email.indexOf("lowstr")>0)returnfalse;
returntrue;
}
publicsynchronizedbooleanisemailstr(Stringemail)
{
if(email==null)returnfalse;
if(email.indexOf("@")==-1||email.indexOf(".")==-1||email.length()<6)returnfalse;
returntrue;
}
publicsynchronizedbooleanisqqstr(Stringqq)
{
if(qq==null)returnfalse;
if(qq.length()>12)returnfalse;
if(qq.length()<5)returnfalse;
for(inti=0;i<qq.length();i++)
if(!(((int)qq.charAt(i))<=57&&((int)qq.charAt(i))>=48))returnfalse;
returntrue;
}
publicsynchronizedbooleanisnumstr(Stringnum)
{
if(num==null)returnfalse;
if(num.length()<1)returnfalse;
for(inti=0;i<num.length();i++)
if(!(((int)num.charAt(i))<=57&&((int)num.charAt(i))>=48))returnfalse;
returntrue;
}
publicsynchronizedStringuserstrlow(Stringuser)
{
Stringnewuserstr=user.trim();
char[]lowstr={,",
,&, ,,<,>,/,,#};
for(inti=0;i<lowstr.length;i++)
newuserstr=newuserstr.replace(lowstr[i],+);
returnnewuserstr;
}
publicsynchronizedbooleanuserstrchk(Stringuser)
{
Stringnewuserstr=user.trim();
char[]lowstr={,",
,&, ,,<,>,/,,#,~,`,!,@,$,%,^,*,(,),-,_,+,=,|,?,,,;,.};
for(inti=0;i<lowstr.length;i++)
newuserstr=newuserstr.replace(lowstr[i],+);
return(user.equals(newuserstr))?true:false;
}
publicsynchronizedbooleanistelstr(Stringtel)
{
if(tel==null)returnfalse;
if(tel.length()<1)returnfalse;
if(tel.length()>32)returnfalse;
for(inti=0;i<tel.length();i++)
if(!(((int)tel.charAt(i))<=57&&((int)tel.charAt(i))>=48))if(tel.charAt(i)!=-)returnfalse;
returntrue;
}
publicsynchronizedbooleanurlcheck(Stringurl)
{
if(url==null)returnfalse;
if(url.length()<10)returnfalse;
Stringurls=url.toLowerCase();
if(!urls.startsWith("http://"))returnfalse;
if(url.indexOf("<")>0||url.indexOf(">")>0)returnfalse;
returntrue;
}
publicsynchronizedStringisotogbk(Stringiso)throwsException
{
if(iso!=null)return(newString(iso.getBytes(isostr),gbkstr));
if(iso.length()<1)return"";
returnnull;
}
publicsynchronizedStringgbktoiso(Stringgbk)throwsException
{
if(gbk!=null)return(newString(gbk.getBytes(gbkstr),isostr));
if(gbk.length()<1)return"";
returnnull;
}
publicsynchronizedStringHTMLcode(StringTXTcode)
{
Stringnewstr="";
if(TXTcode==null)return"";
newstr=TXTcode;
newstr=replace(newstr,"&","&");
newstr=replace(newstr,""",""");
newstr=replace(newstr,"","");
newstr=replace(newstr,"<","<");
newstr=replace(newstr,">",">");
newstr=replace(newstr,"","'");
returnnewstr;
}
publicsynchronizedStringUnhtmlcode(Stringstr)
{
Stringnewstr="";
if(str==null)return"";
if(str.length()<1)return"";
newstr=str;
newstr=replace(newstr,"&","&");
//newstr=replace(newstr,""",""");
newstr=replace(newstr,"","");
newstr=replace(newstr,""",""");
//newstr=replace(newstr,"<","<");
//newstr=replace(newstr,">",">");
newstr=replace(newstr,"'","");
returnnewstr;
}
publicsynchronizedStringUnhtmlcodea(Stringstr)
{
Stringnewstr="";
if(str==null)return"";
if(str.length()<1)return"";
newstr=str;
newstr=replace(newstr,"&","&");
newstr=replace(newstr,""",""");
newstr=replace(newstr,"","");
newstr=replace(newstr,"<","<");
newstr=replace(newstr,">",">");
newstr=replace(newstr,"'","");
returnnewstr;
}
publicsynchronizedStringdostrcut(Stringoldstr,intlength)
{
inti=0;
intj=0;
intk=0;
Stringnewstr="";
if(oldstr==null)return"";
if(length<=0)return"";
for(i=0;i<oldstr.length();i++)
{
if(oldstr.charAt(i)==
)j=0;
elseif(((int)(oldstr.charAt(i)))>255)j+=2;
elsej++;
if((j/2)>=length)
{
newstr=newstr.concat(oldstr.substring(k,i)+"
");
k=i;
j=0;
}
}
newstr=newstr.concat(oldstr.substring(k)+"
");
returnnewstr;
}
publicsynchronizedStringinttodateshow(intdatenum)
{
intyear=0;
intmonth=0;
intday=0;
inthour=0;
intminute=0;
intsecond=0;
Stringdatestr="";
java.util.Dated;
d=newjava.util.Date((long)(datenum)*1000);
java.util.Calendards=java.util.Calendar.getInstance();
ds.setTime(d);
year=ds.get(java.util.Calendar.YEAR);
month=ds.get(java.util.Calendar.MONTH);
day=ds.get(java.util.Calendar.DATE);
hour=ds.get(java.util.Calendar.HOUR_OF_DAY);
minute=ds.get(java.util.Calendar.MINUTE);
second=ds.get(java.util.Calendar.SECOND);
datestr=Integer.toString(year)+"/"+Integer.toString(1+month)+"/"+Integer.toString(day);
returndatestr;
}
publicsynchronizedStringnowdateshow()
{
intyear=0;
intmonth=0;
intday=0;
inthour=0;
intminute=0;
intsecond=0;
Stringdatestr="";
java.util.Calendards=java.util.Calendar.getInstance();
year=ds.get(java.util.Calendar.YEAR);
month=ds.get(java.util.Calendar.MONTH);
day=ds.get(java.util.Calendar.DATE);
hour=ds.get(java.util.Calendar.HOUR_OF_DAY);
minute=ds.get(java.util.Calendar.MINUTE);
second=ds.get(java.util.Calendar.SECOND);
datestr=Integer.toString(year)+"/"+Integer.toString(1+month)+"/"+Integer.toString(day);
returndatestr;
}
publicsynchronizedjava.util.Dateinttodate(intdatenum)
{
intyear=0;
intmonth=0;
intday=0;
Stringdatestr="";
java.util.Dated;
d=newjava.util.Date((long)(datenum)*1000);
returnd;
}
publicsynchronizedintdatetoint()
{
java.util.Dated=null;
longds=0;
d=newjava.util.Date();
ds=d.getTime();
return(int)(ds/1000);
}
publicsynchronizedintdatetoint(java.util.Dated)
{
longds=0;
ds=d.getTime();
return(int)(ds/1000);
}
publicsynchronizedStringoverlengthcut(Stringstr,intlength)
{
inti=0;
intj=0;
if(str==null)return"";
if(length<0)return"";
if(str.length()<=length)returnstr;
for(i=0;i<str.length();i++)
{
if(((int)(str.charAt(i)))>255)j+=2;
elsej++;
if((j/2)>=length)
{
returnstr.substring(0,i);
}
}
returnstr;
}
publicsynchronizedStringreplace(Stringstr,Stringsuba,Stringsubb)
{
Stringnewstr="";
intstart=0;
intoffset=0;
intsubalength=0;
intstrlength=0;
if(str==null||suba==null||subb==null)returnstr;
if(suba.equals(subb))returnstr;
if(str.length()<suba.length()||str.length()<subb.length())returnstr;
if(str.length()>0&&suba.length()>0&&subb.length()>0)
{
subalength=suba.length();
strlength=str.length();
while(true)
{
if(str.indexOf(suba)<0)break;
if(offset>strlength)break;
start=str.indexOf(suba,offset);
if(start<offset)break;
newstr=newstr.concat(str.substring(offset,start));
newstr=newstr.concat(subb);
offset=start+subalength;
}
newstr=newstr.concat(str.substring(offset));
returnnewstr;
}
else
{
returnstr;
}
}
}
他们对jsp,servlet,javabean进行封装就是为了展示他们的某个思想,与java的开发并没有必然的关系,也不见得在所以情况下,别人使用起来会简单。 |
|