messFun.java
上传用户:manager48
上传日期:2022-07-31
资源大小:997k
文件大小:3k
- /*****************************************************************
- * Date:2007-04-27 *
- * File:messFun.java *
- * Author:jezz *
- *****************************************************************/
- package wm.bean;
- import java.sql.*;
- import java.util.LinkedList;
- import java.util.List;
- import wm.bean.DB;
- public class messFun{
-
- public messFun(){
- }
- //判断登陆验证
- public boolean checkLogin(String username,String password){
-
- DB db =new DB();
- boolean flag=false;
- String sql="select username,password from admin where username='"+username+"' && password='"+password+"'";
- try{
- ResultSet rs=db.executeQuery(sql);
- if(rs.next())
- flag=true;
- else
- flag=false;
- db.all_close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- return flag;
- }
- //插入留言
- public boolean addMess(String ip,String email,String sj,String content,String restore,String xm)
- {
- DB db =new DB();
- boolean flag=true;
- email=this.filter(email);//过滤
- content=this.filter(content);
- xm=this.filter(xm);
- email=this.ex_chinese(email);
- content=this.ex_chinese(content);
- xm=this.ex_chinese(xm);
- String sql="insert into liuyan_temp(ip,email,sj,content,restore,xm) values('"+ip+"','"+email+"','"+sj+"','"+content+"','"+restore+"','"+xm+"')";
- try{
- db.executeUpdate(sql);
- db.all_close();
- }
- catch(Exception ex)
- {
- flag=false;
- ex.printStackTrace();
- }
- return flag;
- }
- //添加回复
- public boolean postMess(String id,String restore)
- {
- DB db=new DB();
- boolean flag=true;
- restore=this.filter(restore);
- restore=this.ex_chinese(restore);
- String sql="update liuyan_temp set restore='"+restore+"',restore_time='"+this.gettime()+"' where id='"+id+"'";
- try{
- db.executeUpdate(sql);
- db.all_close();
- }
- catch(Exception ex)
- {
- flag=false;
- ex.printStackTrace();
- }
- return flag;
- }
- //过滤留言
- public static String filter(String text){
- if(text != null){
- text = text.replaceAll("<", "<");
- text = text.replaceAll(">", ">");
-
- text = text.replaceAll("rn", "n");
- text = text.replaceAll("r", "n");
- text = text.replaceAll("n", "r");
- text = text.replaceAll("r{2,}","n</p><p>n");
- text = text.replaceAll("r","<br />");
- }
- return text;
- }
- public boolean validLength(String item,int minLen,int maxLen)
- {//判断字符范围
- if((item.length()>=minLen)&&(item.length()<=maxLen))
- return true;
- else
- return false;
- }
-
- public boolean validNum(String str)
- {
- int i;
- boolean flag=false;
- if(str.length()>0)
- for(i=0;i<str.length()-1;i++)
- {
- if (str.charAt(i)>='0'&&str.charAt(i)<='9')
- //if(i==str.length()-1)
- return flag=true;
- else
- return flag=false;
- //break;
- }
- return flag;
- }
- public String gettime() {//生成详细的时间
- String datestr = "" ;
- try {
- java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy年MM月dd日 HH点ss分") ;
- java.util.Date date = new java.util.Date() ;
- datestr = df.format(new java.util.Date()) ;
- }
- catch (Exception ex) {
- }
- return datestr ;
- }
- public String ex_chinese(String str){//转成中文
- if(str==null){
- str ="" ;
- }
- else{
- try {
- str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
- }
- catch (Exception ex) {
- }
- }
- return str ;
- }
- }