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

📄 updata.jsp

📁 是一个客户管理系统
💻 JSP
字号:

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<HTML>
<BODY bgcolor=white ><Font size=3>
<p>
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%!//处理字符串的一个常用方法:
    int t[]=new int[2];
    int d[]=new int[2];
    String answer=null;
    public String getString(String s)
     { if(s==null) s="";
       try {byte a[]=s.getBytes("ISO-8859-1");
            s=new String(a);
           }
       catch(Exception e)
           { }
       return s;
     }
 %>
<% String s1=response.encodeRedirectURL("check.jsp");
   String s2=response.encodeRedirectURL("admin.jsp");
%>

<% //为了防止客户直接进入该页面,首先从session对象获取密码和帐号信息:
    String name="",password="";
    if(session.isNew())
       {//如果直接进入该页面就再连接到登录页面:
         response.sendRedirect("admin.jsp"); 
       }
    else
       { name=(String)session.getAttribute("name");
         password=(String)session.getAttribute("password");
         password=getString(password); 
         name=getString(name);
       }
    Connection con4=null;
    Statement sql4=null;
    ResultSet rs4=null;
    boolean boo=false;
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       }
   catch(ClassNotFoundException event){}
       try { con4=DriverManager.getConnection("jdbc:odbc:mis");
       sql4=con4.createStatement();
       String condition9="SELECT * FROM admin WHERE adminname = "+"'"+name+"'";
       rs4 =sql4.executeQuery(condition9);
       while(rs4.next())
            { String n=rs4.getString("adminname");
              String s=rs4.getString("adminpwd");
              if(name.equals(n)&&password.equals(s))
                {boo=true; break;
                }
            }
         con4.close(); 
	}
    catch(SQLException e1) {}
%>
  <%  
    if(boo)
{
    String newid=request.getParameter("id");
          if(newid==null)
            {newid="";
            }
     int z=0;
     int flag=1;      
     String temp=newid;
     try{ z=Integer.valueOf(temp).intValue();
        }
     catch(NumberFormatException e)
                         {
                          flag=0;
                      out.print("用户id必须为数字型,2秒后返回重新操作"+"<BR>");   
                      out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");    
                         }

         int i=0;
         double result=0;
         String newtel=null;
         newtel=request.getParameter("tel");
      int tellen=newtel.length();
      int telsign=1;
      if(tellen==0)
       {
             newtel="空";
             telsign=0;
       }
      if(telsign==1)
     {
         i=0;

         int t[]=new int[2];
         String answer=null;

            if(newtel!=null)
               { StringTokenizer  fenxi=new StringTokenizer(newtel,"-");
                 while(fenxi.hasMoreTokens())
                     { 
                       String temp1=fenxi.nextToken();
                       try{ t[i]=Integer.valueOf(temp1).intValue();
                              i++;
                           }
                      catch(NumberFormatException et)
                         {
                      out.print("电话号码格式错误,2秒后返回重新操作"+"<BR>");   
                      out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");      
                          flag=0;        
                         }
                      }
                }
             if(t[0]<0||t[0]>9999||t[1]<=0)
              {       flag=0;
                      out.print("电话号码格式错误,2秒后返回重新操作"+"<BR>");   
                      out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");   
               }  
       } 
String newfax=null;
newfax=request.getParameter("fax");
      int faxlen=newfax.length();
      int faxsign=1;
      if(faxlen==0)
       {
             newfax="空";
             faxsign=0;
       }
      if(faxsign==1)
       { 
         i=0;
         result=0;
         int d[]=new int[2];
         answer=null;
         if(newfax!=null)
              { StringTokenizer fenxid=new StringTokenizer(newfax,"-");
                 while(fenxid.hasMoreTokens())
                     { 
                       String tempd=fenxid.nextToken();
                       try{ d[i]=Integer.valueOf(tempd).intValue();
                              i++;
                           }
                      catch(NumberFormatException ed)
                         {
                      out.print("传真号码格式错误,2秒后返回重新操作"+"<BR>");   
                      out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");      
                          flag=0;        
                         }
                      }
                }
             if(d[0]<0||d[0]>9999||d[1]<=0)
              {       flag=0;
                      out.print("传真号码格式错误,2秒后返回重新操作"+"<BR>");   
                      out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");   
               }  
     }


      String newemail=request.getParameter("email");
      int emaillen=newemail.length();
      int emailsign=1;
      if(emaillen==0)
       {
             newemail="空";
             emailsign=0;
       }   
  
if(emailsign==1)
{
    int fp1=0,fp2=0;
    fp1=newemail.indexOf('@',1);
    fp2=newemail.indexOf('.',fp1+1);
    int lenth=0;
    lenth=newemail.length();
    if(fp1<0||fp1>=lenth||fp2<0||fp2>=lenth||fp2==(fp1+1))
       {
          flag=0;
          out.print("E-Mail格式错误,2秒后返回重新操作"+"<BR>");   
          out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");   
       }
}
    String newaddre=request.getParameter("addre");
          if(newaddre==null)
            {newaddre="";
            }
    byte b[]=newaddre.getBytes("ISO-8859-1");
     newaddre=new String(b);

    String newnote=request.getParameter("note");
          if(newnote==null)
            {newnote="";
            }
    byte f[]=newnote.getBytes("ISO-8859-1");
     newnote=new String(f);

    String newname=request.getParameter("na");
          if(newname==null)
            {newname="";
            }
    byte g[]=newname.getBytes("ISO-8859-1");
     newname=new String(g);
     String newpwd=request.getParameter("password");
     if(newpwd==null)
            {newpwd="12345";
            }
      byte a[]=newpwd.getBytes("ISO-8859-1");
      newpwd=new String(a);
    Connection con=null;
    Statement sql=null;
    ResultSet rs=null;
    boolean isEqual;
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e2){}
       try {
       con=DriverManager.getConnection("jdbc:odbc:mis");
       sql=con.createStatement();
       String 
              condition="SELECT * FROM customer WHERE custid = "+z;
              rs=sql.executeQuery(condition);
       if(!rs.next())
              {
                 flag=0;
                 out.print("该用户id不存在,2秒后返回重新操作"+"<BR>");
                 out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=edit.jsp>");                
              }
              else
              {
  if(flag==1)
 {
      int addrelen=newaddre.length();
      if(addrelen==0)
       {
             newaddre=rs.getString(3);
       }
      int namelen=newname.length();
      if(namelen==0)
       {
             newname=rs.getString(2);
       }
      int pwdlen=newpwd.length();
      if(pwdlen==0)
       {
             newpwd=rs.getString(8);
       } 

      int notelen=newnote.length();
      if(notelen==0)
       {
             newnote=rs.getString(7);
       }
      if(telsign==0)
       {
             newtel=rs.getString(4);
       }
      if(faxsign==0)
       {
             newfax=rs.getString(5);
       }
      if(emailsign==0)
       {
             newemail=rs.getString(6);
       }

              String 
              condition2=
              "UPDATE customer SET pwd = "+"'"+newpwd+"'"+"WHERE custid="+z,
              condition3=
              "UPDATE customer SET caddress = "+"'"+newaddre+"'" +"WHERE custid="+z,
              condition4=
              "UPDATE customer SET tel = "+"'"+newtel+"'" +"WHERE custid="+z,
              condition5=
              "UPDATE customer SET fax = "+"'"+newfax+"'" +"WHERE custid="+z,
              condition6=
              "UPDATE customer SET email = "+"'"+newemail+"'" +"WHERE custid="+z,
              condition7=
              "UPDATE customer SET notes = "+"'"+newnote+"'" +"WHERE custid="+z,
              condition8=
              "UPDATE customer SET cname = "+"'"+newname+"'" +"WHERE custid="+z;
       //执行更新操作:
       sql.executeUpdate(condition2);
       sql.executeUpdate(condition3);
       sql.executeUpdate(condition4);
       sql.executeUpdate(condition5);
       sql.executeUpdate(condition6);
       sql.executeUpdate(condition7);
       sql.executeUpdate(condition8);
                 out.print("编辑完成,2秒后返回管理页面");
                 out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=check.jsp>");  
             }
 }
           con.close();
           }
           catch(SQLException e1)
           {  }
}
   else
{
       out.print("请先登陆,系统将于2秒钟后自动返回登陆页面");
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=5;url=admin.jsp>");          
}
     %>
</FONT>
</BODY>
</HTML>

⌨️ 快捷键说明

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