⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selffunction.java

📁 《jsp案例开发》这本书的源代码。包括源代码和相关的具体配置操作步骤。非常不错
💻 JAVA
字号:
<%!
//把串mystr中的单引号“'”换成“''”,处理查询条件中出现单引号的问题。
public String switchquot(String mystr){
    String ch;
    String strall="";
    int n;
    int i;
    n=mystr.length();
    for(i=0;i<=n-1;i++){
      ch=mystr.substring(i,i+1);
      if(ch.equals("'"))
        ch="''";
      strall +=ch;
    }
    return strall;
}

/**<p>Description: 返回字符串temp在str字符串中出现的次数</p> */
public int CharNumInStr(String str,String temp){
	int i=0;
	String t_str=str;
	while(t_str.indexOf(temp)!=-1){
            t_str=t_str.substring(t_str.indexOf(temp)+temp.length(),t_str.length());
            i++;
	}
	return i;
}


//取得日期相关的数据:年、月、日,theDate="YYYYMMDD",
//如果theDate为空,则取系统当前日期。
public String netYear(String theDate)
{    
    if(theDate==null || theDate.length()==0)  //取系统当前日期。
    return("1950");
  else  //认为是 "YYYYMMDD" 形式
    return(theDate.substring(0,4));
}


public String netMonth(String theDate)
{
  if(theDate==null || theDate.length()==0)  //取系统当前日期。
    return( "01");
  else  //认为是 "YYYYMMDD" 形式
    return(theDate.substring(5,7));
}


public String netDay(String theDate)
{  
  if(theDate==null || theDate.length()==0)  //取系统当前日期。
    return( "01");
  else  //认为是 "YYYYMMDD" 形式
    return(theDate.substring(6));
}


public String netDay1(String theDate)
{  
  if(theDate==null || theDate.length()==0)  //取系统当前日期。
    return( "01");
  else  //认为是 "YYYYMMDD" 形式
    return(theDate.substring(8,10));
}


//*获得系统的当前日期 格式: year-month-date hour:minute:second*/
	public String getCdate(){
		java.util.Date cdate=new java.util.Date();
		String temp="";
		int year=cdate.getYear()+1900;//输出年份
		temp=temp+year;
		int month=cdate.getMonth()+1;//输出月份
		if(month<10){
			temp=temp+"0"+month;
		}else{
			temp=temp+month;
		}
		int date=cdate.getDate();//获得代表日期得日值
		if(date<10){
			temp=temp+"0"+date;
		}else{
			temp=temp+date;
		}
		int hour=cdate.getHours();//获得代表时间得小时值
		if(date<10){
			temp=temp+"0"+hour;
		}else{
			temp=temp+hour;
		}

		int minute=cdate.getMinutes();//获得代表时间得分值
		if(date<10){
			temp=temp+"0"+minute;
		}else{
			temp=temp+minute;
		}
		int second=cdate.getSeconds();//获得代表时间得秒值
		if(date<10){
			temp=temp+"0"+second;
		}else{
			temp=temp+second;
		}
		temp=year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
		return temp;
	}

/**
 * <p>Title:CharNumInStr </p>
 * <p>Description: 返回系统的当前日期</p>
 * <p>Copyright: cnc◎njtu.edu.cn</p>
 * <p>Company: cnc </p>
 * @author 张志国
 * @version 1.0
 */
	//*获得系统的当前日期 格式: year-month-date hour:minute:second*/
	public String get_date(){
		java.util.Date cdate=new java.util.Date();
		String temp="";
		int year=cdate.getYear()+1900;//输出年份
		temp=temp+year;
		int month=cdate.getMonth()+1;//输出月份
		if(month<10){
			temp=temp+"-"+"0"+month;
		}else{
			temp=temp+"-"+month;
		}
		int date=cdate.getDate();//获得代表日期得日值
		if(date<10){
			temp=temp+"-"+"0"+date;
		}else{
			temp=temp+"-"+date;
		}
		int hour=cdate.getHours();//获得代表时间得小时值
		if(hour<10){
			temp=temp+" "+"0"+hour;
		}else{
			temp=temp+" "+hour;
		}

		int minute=cdate.getMinutes();//获得代表时间得分值
		if(minute<10){
			temp=temp+":"+"0"+minute;
		}else{
			temp=temp+":"+minute;
		}
		int second=cdate.getSeconds();//获得代表时间得秒值
		if(second<10){
			temp=temp+":"+"0"+second;
		}else{
			temp=temp+":"+second;
		}
		//temp=temp+year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
		return temp;
	}


	public String get_date1(){
            java.util.Date cdate=new java.util.Date();
            String temp="";
            int year=cdate.getYear()+1900;//输出年份
            temp=temp+year;
            int month=cdate.getMonth()+1;//输出月份
            if(month<10){
                  temp=temp+"0"+month;
            }else{
                  temp=temp+month;
            }
            int date=cdate.getDate();//获得代表日期得日值
            if(date<10){
                  temp=temp+"0"+date;
            }else{
                  temp=temp+date;
            }
            int hour=cdate.getHours();//获得代表时间得小时值
            if(hour<10){
                  temp=temp+"0"+hour;
            }else{
                  temp=temp+hour;
            }
            int minute=cdate.getMinutes();//获得代表时间得分值
            if(minute<10){
                  temp=temp+"0"+minute;
            }else{
                  temp=temp+minute;
            }
            int second=cdate.getSeconds();//获得代表时间得秒值
            if(second<10){
                  temp=temp+"0"+second;
            }else{
                  temp=temp+second;
            }
            return temp;
      }

//获得某月的天数
public int getdays(int y,int m)
{
  if(m==2)
  {
    if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
      return(29);
    else
      return(28);
  }
  else if(m==4 || m==6 || m==9 || m==11)
  {
    return(30);
  }
  else
  {
    return(31);
  }
}


//处理中文问题的自定义函数    
public String getStr(String str)
{
	try
	{       
		String temp_p=str;

		byte[] temp_t=temp_p.getBytes("ISO8859-1");
		String temp=new String(temp_t);

		return temp;
	}
	catch(Exception e)
 	{
		e.printStackTrace();
	}
	return "null";
}


//是否为闰年
public boolean isrunnian(int yyyy)
{
  return((yyyy % 4 == 0 && yyyy % 100 != 0) || (yyyy % 400 == 0));  
}

//获取删除条件。
public String setsqlwheredelete(String[] chkvalue)
{
  int i;
  String result; 
  char ch;
  result="";
  if(chkvalue!=null)
  {
    result=chkvalue[0];
    for(i=1;i<chkvalue.length;i++)
    {
      result=result+" or "+chkvalue[i];
    }
  }
  return(result);
}

public String setsqlwheredelete1(String[] chkvalue,String option)
{
  int i;
  String result; 
  char ch;
  result="";
  if(chkvalue!=null)
  {
    result=option+"="+chkvalue[0];
    for(i=1;i<chkvalue.length;i++)
    {
      result=result+" or "+option+"="+chkvalue[i];
    }
  }
  return(result);
}

/**
 * <p>Title:to_br_html </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003 </p>
 * <p>Company: cnc</p>
 * @author zw
 * @version 1.0
 */

//处理输入的信息内容
//该函数将字符串mystr中的'\n','\r'转换为<br>,

public static String returnToBr(String mystr){

	if (mystr == null || mystr.equals(""))
        {
		return mystr;
	}

	mystr=mystr.trim();
	StringBuffer stemp = new StringBuffer();
	int i = 0;
	while(i <= mystr.length()-1)
        {
		if (mystr.charAt(i) == '\n' || mystr.charAt(i) == '\r')
                    {int j=i+1;
                    if (mystr.charAt(j) == '\n' || mystr.charAt(j) == '\r')
                     {stemp =stemp.append("<br>&nbsp;&nbsp;&nbsp;&nbsp;");
                     i++;}
                     else
                     stemp =stemp.append("<br>");}

		else if (mystr.charAt(i) == ' ')
		//	stemp = stemp.append("&nbsp;");//' '转换为&nbsp;
			stemp = stemp.append(" ");
			else
				stemp = stemp.append(mystr.substring(i,i+1));
		i++;
	}
	String resultstr;
	resultstr ="&nbsp;&nbsp;&nbsp;&nbsp;" + stemp.toString();
        return  resultstr;

}
//处理输入的信息内容
//该函数将字符串mystr中的'<','>'转换为"&lt;"及"&gt;";
public static String returnToHTML(String mystr){
	if (mystr == null || mystr.equals("")){
		return mystr;
	}

	StringBuffer stemp = new StringBuffer();
	int i = 0;
	while(i <= mystr.length()-1){
		if (mystr.charAt(i) == '<')
			stemp =stemp.append("&lt;");
		else if (mystr.charAt(i) == '>')
			stemp = stemp.append("&gt;");
		     else
			stemp = stemp.append(mystr.substring(i,i+1));
		i++;
	}
	String resultstr;
	resultstr = stemp.toString();
	return resultstr;

}


//若str 为null或者空串时转换为一个空格,其它不改变
public String nulltoblank(String str)
{
  if(str==null)
    return(" ");
  else	if(str.equals(""))
  			return(" ");
		else
    		return(str);
}

public String nulltospace(String str)
{
  if(str==null)
    return("");
  else
    return(str);
}

//得到两个日期之间有多少天
public  long getDays(String t1,String t2){//t1,t2格式为yyyy-mm-dd(1978-09-08)
		int y1,y2,m2,m1,d1,d2;
		long days;//两个日期之间的天数
		long time;
		y1=Integer.parseInt(t1.substring(0,4))-1900;
		y2=Integer.parseInt(t2.substring(0,4))-1900;
		m1=Integer.parseInt(t1.substring(t1.indexOf("-")+1,t1.lastIndexOf("-")))-1;
		m2=Integer.parseInt(t2.substring(t2.indexOf("-")+1,t2.lastIndexOf("-")))-1;
	    d1=Integer.parseInt(t1.substring(t1.lastIndexOf("-")+1,t1.length()));
	    d2=Integer.parseInt(t2.substring(t2.lastIndexOf("-")+1,t2.length()));
        if(((new java.sql.Date(y1,m1,d1)).getTime()-(new java.sql.Date(y2,m2,d2)).getTime())<0)
           time=-((new java.sql.Date(y1,m1,d1)).getTime()-(new java.sql.Date(y2,m2,d2)).getTime());
		else
			time=((new java.sql.Date(y1,m1,d1)).getTime()-(new java.sql.Date(y2,m2,d2)).getTime());
	    days=time/86400000;
        return days;
	}

//字符串替换函数,将str字符串里的oldstr字符串替换为newstr字符串
public  String replace(String str,String oldstr,String newstr){//将str字符串里的oldstr字符串替换为newstr字符串
		String tempstr;
		
		if(str.indexOf(oldstr)==-1)//没有oldstr字符串
		  return str;
		  
		tempstr=str.substring(0,str.indexOf(oldstr))+newstr;	
		str=str.substring(str.indexOf(oldstr)+oldstr.length(),str.length());
		
		while(str.indexOf(oldstr)!=-1){
		tempstr+=str.substring(0,str.indexOf(oldstr))+newstr;	
		str=str.substring(str.indexOf(oldstr)+oldstr.length(),str.length());
	    
	    }
	    return tempstr+str;
	}
	

%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -