国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

以前編寫JSP網站時寫的一些工具函數

2024-09-05 00:20:21
字體:
來源:轉載
供稿:網友
中國最大的web開發資源網站及技術社區,

初學jsp時,寫了一些工具函數因為不太會用java下的正則表達式也只能這么寫啦!發出來讓大家批評批評提點意見!有幾個函數不算是自己寫的希望愛挑剌的朋友嘴下留情!我是新手我怕誰,臉皮不行的人水平也上不去呀.嘻嘻..

package mxzc.web.strctrl;
public class stringctrl
{/********************************************
public synchronized string htmlcode(string txtcode)   功能:文本替換
public synchronized string unhtmlcode(string str)   功能:(不完全)反文本替換
public synchronized string unhtmlcodea(string str)   功能:反文本替換
public synchronized boolean emailcheck (string email)   功能:檢查一個字符串是否符合e-mail
public synchronized boolean isemailstr(string email)   功能:檢查一個字符串是否符合e-mail
public synchronized boolean isqqstr(string qq)    功能:檢查一個字符串是否符合qq
public synchronized boolean isnumstr(string num)   功能:檢查一個字符串是否為一數字串
public synchronized string userstrlow(string user)   功能:替換用戶名中不合法的部分
public synchronized boolean userstrchk(string user)   功能:檢查字符串是否符合用戶名法則
public synchronized boolean istelstr(string tel)   功能:檢查字符串是否為tel
public synchronized boolean urlcheck(string url)   功能:檢查字符串是否為url
public synchronized string isotogbk(string iso)    功能:iso9006-1碼轉換為gbk
public synchronized string gbktoiso(string gbk)    功能:gbk碼轉換為iso9006-1
public synchronized string dostrcut(string oldstr,int length)  功能:按漢字長換行(英文按半個字長)
public synchronized string inttodateshow(int datenum)   功能:將1900年至時間的秒數換為日期字符串
public synchronized string nowdateshow()    功能:顯示當前日期
public synchronized java.util.date inttodate(int datenum)  功能:將秒數轉換為日期
public synchronized int datetoint()     功能:將時間換為從1900年至今的秒數
public synchronized int datetoint(java.util.date d)   功能:將時間換為從1900年至時間的秒數
public synchronized string overlengthcut(string str,int length)  功能:截取前幾個字符,單位為漢字字長
public synchronized string replace(string str,string suba,string subb) 功能:字符串替換
*********************************************/
private static final string isostr="iso8859-1";
private static final string gbkstr="gbk";
public stringctrl()
{
}
public synchronized boolean emailcheck (string email)
{
if(email==null)return false;
if(email.length()<6)return false;
if(email.indexof("@")<2)return false;
if(email.indexof(".")<4)return false;
if(email.endswith(".")||email.endswith("@"))return false;
if(email.lastindexof("@")>email.lastindexof(".")-1)return false;
if(email.lastindexof("@")!=email.indexof("@"))return false;
string[] lowstr={"/'","/"","/n","&","/t","/r","<",">","/","http://","#"};
for(int i=0;i<lowstr.length;i++)if(email.indexof("lowstr")>0)return false;
return true;
}
public synchronized boolean isemailstr(string email)
{
if(email==null)return false;
if(email.indexof("@")==-1||email.indexof(".")==-1||email.length()<6)return false;
return true;
}
public synchronized boolean isqqstr(string qq)
{
if(qq==null)return false;
if(qq.length()>12)return false;
if(qq.length()<5)return false;
for(int i=0;i<qq.length();i++)
if(!(((int)qq.charat(i))<=57&&((int)qq.charat(i))>=48))return false;
return true;
}
public synchronized boolean isnumstr(string num)
{
if(num==null)return false;
if(num.length()<1)return false;
for(int i=0;i<num.length();i++)
if(!(((int)num.charat(i))<=57&&((int)num.charat(i))>=48))return false;
return true;
}
public synchronized string userstrlow(string user)
{
string newuserstr=user.trim();
char[] lowstr={'/'','/"','/n','&','/t','/r','<','>','/','//','#'};
for(int i=0;i<lowstr.length;i++)
newuserstr=newuserstr.replace(lowstr[i],'+');
return newuserstr;
}
public synchronized boolean userstrchk(string user)
{
string newuserstr=user.trim();
char[] lowstr={'/'','/"','/n','&','/t','/r','<','>','/','//','#','~','`','!','@','$','%','^','*','(',')','-','_','+','=','|','?',',',';','.'};
for(int i=0;i<lowstr.length;i++)
newuserstr=newuserstr.replace(lowstr[i],'+');
return (user.equals(newuserstr))?true:false;
}
public synchronized boolean istelstr(string tel)
{
if(tel==null)return false;
if(tel.length()<1)return false;
if(tel.length()>32)return false;
for(int i=0;i<tel.length();i++)
if(!(((int)tel.charat(i))<=57&&((int)tel.charat(i))>=48))if(tel.charat(i)!='-')return false;
return true;
}
public synchronized boolean urlcheck(string url)
{
if(url==null)return false;
if(url.length()<10)return false;
string urls=url.tolowercase();
if(!urls.startswith("http://"))return false;
if(url.indexof("<")>0||url.indexof(">")>0)return false;
return true;
}
public synchronized string isotogbk(string iso)throws exception
{
 if(iso!=null)return (new string(iso.getbytes(isostr),gbkstr));
 if(iso.length()<1)return "";
 return null;
}
public synchronized string gbktoiso(string gbk)throws exception
{
 if(gbk!=null)return (new string(gbk.getbytes(gbkstr),isostr));
 if(gbk.length()<1)return "";
 return null;
}
public synchronized string htmlcode(string txtcode)
{
 string newstr="";
 if(txtcode==null)return "";
 newstr=txtcode;
 newstr=replace(newstr,"&","&amp;");
 newstr=replace(newstr,"/"","&quot;");
 newstr=replace(newstr," ","&nbsp;");
 newstr=replace(newstr,"<","&lt;");
 newstr=replace(newstr,">","&gt;");
 newstr=replace(newstr,"/'","&#00039;");
 return newstr;
}
public synchronized string unhtmlcode(string str)
{
 string newstr="";
 if(str==null)return "";
 if(str.length()<1)return "";
 newstr=str;
 newstr=replace(newstr,"&amp;","&");
 //newstr=replace(newstr,"&quot;","/"");
 newstr=replace(newstr,"&nbsp;"," ");
 newstr=replace(newstr,"&quot;","/"");
 //newstr=replace(newstr,"&lt;","<");
 //newstr=replace(newstr,"&gt;",">");
 newstr=replace(newstr,"&#00039;","/'");
 return newstr;
}
public synchronized string unhtmlcodea(string str)
{
 string newstr="";
 if(str==null)return "";
 if(str.length()<1)return "";
 newstr=str;
 newstr=replace(newstr,"&amp;","&");
 newstr=replace(newstr,"&quot;","/"");
 newstr=replace(newstr,"&nbsp;"," ");
 newstr=replace(newstr,"&lt;","<");
 newstr=replace(newstr,"&gt;",">");
 newstr=replace(newstr,"&#00039;","/'");
 return newstr;
}
public synchronized string dostrcut(string oldstr,int length)
{
 int i=0;
 int j=0;
 int k=0;
 string newstr="";
 if(oldstr==null)return "";
 if(length<=0)return "";
 for(i=0;i<oldstr.length();i++)
 {
  if(oldstr.charat(i)=='/n')j=0;
  else if(((int)(oldstr.charat(i)))>255)j+=2;
  else j++;
  if((j/2)>=length)
  {
   newstr=newstr.concat(oldstr.substring(k,i)+"/n");
   k=i;
   j=0;
  }
 }
 newstr=newstr.concat(oldstr.substring(k)+"/n");
 return newstr;
}
public synchronized string inttodateshow(int datenum)
{
 int year=0;
 int month=0;
 int day=0;
 int hour=0;
 int minute=0;
 int second=0;
 string datestr="";
 java.util.date d;
 d=new java.util.date((long)(datenum)*1000);
 java.util.calendar ds=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);
 return datestr;
}
public synchronized string nowdateshow()
{
 int year=0;
 int month=0;
 int day=0;
 int hour=0;
 int minute=0;
 int second=0;
 string datestr="";
 java.util.calendar ds=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);
 return datestr;
}
public synchronized java.util.date inttodate(int datenum)
{
 int year=0;
 int month=0;
 int day=0;
 string datestr="";
 java.util.date d;
 d=new java.util.date((long)(datenum)*1000);
 return d;
}
public synchronized int datetoint()
{
 java.util.date d=null;
 long ds=0;
 d=new java.util.date();
 ds=d.gettime();
 return (int)(ds/1000);
}
public synchronized int datetoint(java.util.date d)
{
 long ds=0;
 ds=d.gettime();
 return (int)(ds/1000);
}
public synchronized string overlengthcut(string str,int length)
{
 int i=0;
 int j=0;
 if(str==null)return "";
 if(length<0)return "";
 if(str.length()<=length)return str;
 for(i=0;i<str.length();i++)
 {
  if(((int)(str.charat(i)))>255)j+=2;
  else j++;
  if((j/2)>=length)
  {
   return str.substring(0,i);
  }
 }
 return str;
}
public synchronized string replace(string str,string suba,string subb)
{
string newstr="";
int start=0;
int offset=0;
int subalength=0;
int strlength=0;
if(str==null||suba==null||subb==null)return str;
if(suba.equals(subb))return str;
if(str.length()<suba.length()||str.length()<subb.length())return str;
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));
 return newstr;
}
else
{
 return str;
}
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 余庆县| 阿鲁科尔沁旗| 延庆县| 泌阳县| 镇沅| 托克逊县| 达日县| 邵阳市| 三亚市| 平遥县| 同江市| 垣曲县| 固阳县| 大兴区| 平乐县| 于田县| 寻甸| 封开县| 郸城县| 临沂市| 察哈| 四川省| 庄河市| 枞阳县| 彭水| 华容县| 广南县| 常山县| 宜章县| 兴安盟| 紫金县| 丹凤县| 德州市| 丰都县| 汉中市| 柳河县| 利辛县| 新营市| 正定县| 海盐县| 合川市|