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

📄 insertsample.jsp

📁 是一个客户管理系统
💻 JSP
字号:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.sql.*"%>
<HTML>
<BODY bgcolor=white ><Font size=3>
<p>
<%!//处理字符串的一个常用方法:
    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;
     }
    int a[]=new int[3];
          String answer=null;
    String state="0";
 %>
<% 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)
{

    int i=0;
         boolean g=true;
         boolean timesign=true;
         String s=null;
         double result=0;
         int a[]=new int[3];
         String answer=null;
         int flag=1;
         s=request.getParameter("ltime");
         int timelen=s.length();
      if(timelen==0)
       {
                          flag=0;
                          timesign=false;
                          out.print("完成日期不可以为空,2秒后返回重新操作");
                          out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");  
       }
      if(timesign)
       {
            if(s!=null)
               { StringTokenizer  fenxi=new StringTokenizer(s,"-");
                 while(fenxi.hasMoreTokens())
                     { 
                       String temp=fenxi.nextToken();
                       try{ a[i]=Integer.valueOf(temp).intValue();
                              i++;
                           }
                      catch(NumberFormatException e)
                         {
       out.print("日期格式错误,2秒后返回重新操作");   
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");      
                          flag=0;        
                         }
                      }
            if(a[0]<2000||a[0]>3000||a[1]>12||a[1]<1||a[2]>30||a[2]<1)
                        {
       out.print("日期格式错误,2秒后返回重新操作");   
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");     
                           flag=0;                 
                        }
                 }
          
         Calendar cal= Calendar.getInstance();
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
         String mDateTime=formatter.format(cal.getTime());
         SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy");
         SimpleDateFormat formatter2 = new SimpleDateFormat("MM");
         SimpleDateFormat formatter3 = new SimpleDateFormat("dd");
         SimpleDateFormat formatter4 = new SimpleDateFormat("HH");
         SimpleDateFormat formatter5 = new SimpleDateFormat("mm");
         SimpleDateFormat formatter6 = new SimpleDateFormat("ss");
         String mDateTime1=formatter1.format(cal.getTime());
         String mDateTime2=formatter2.format(cal.getTime());
         String mDateTime3=formatter3.format(cal.getTime());
         String mDateTime4=formatter4.format(cal.getTime());
         String mDateTime5=formatter5.format(cal.getTime());
         String mDateTime6=formatter6.format(cal.getTime());
         int n=(int)(Math.random()*100)+1;
         String sno=null;
         sno=mDateTime2.concat(mDateTime3);
         sno=sno.concat(mDateTime4);
         sno=sno.concat(mDateTime5);
         sno=sno.concat(mDateTime6);
           


    String newid=request.getParameter("id");
          if(newid==null)
            {newid="";
            }
     int x=0;     
     String temp=newid;
     try{ x=Integer.valueOf(temp).intValue();
        }
     catch(NumberFormatException e)
                         {
                          flag=0;
       out.print("用户id必须为数字字符,2秒后返回重新操作");   
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");                             
                         }

    String newpcode=request.getParameter("pid");
          if(newpcode==null)
            {newpcode="";
            }
    byte h[]=newpcode.getBytes("ISO-8859-1");
     newpcode=new String(h);   
 
    String newcno=request.getParameter("cno");
          if(newcno==null)
            {newcno="";
            }
    byte b[]=newcno.getBytes("ISO-8859-1");
     newcno=new String(b);  

    String newopt=request.getParameter("opt");
          if(newopt==null)
            {newopt="";
            }
    byte c[]=newopt.getBytes("ISO-8859-1");
     newopt=new String(c);
    
    String newnote=request.getParameter("note");
          if(newnote==null)
            {newnote="";
            }
    byte d[]=newnote.getBytes("ISO-8859-1");
     newnote=new String(d); 
     
    int idlen=newid.length();
      if(idlen==0)
       {
                          flag=0;
                          out.print("用户id不可以为空,2秒后返回重新操作");
                          out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");  
       }
    int cnolen=newcno.length();
      if(cnolen==0)
       {
                          flag=0;
                          out.print("色号不可以为空,2秒后返回重新操作");
                          out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");  
       }
    int pcodelen=newpcode.length();
      if(pcodelen==0)
       {
                          flag=0;
                          out.print("产品名称不可以为空,2秒后返回重新操作");
                          out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");  
       }

      int optlen=newopt.length();
      if(optlen==0)
       {
             newopt="空";
       }
      int notelen=newnote.length();
      if(notelen==0)
       {
             newnote="空";
       }     
   
    


%>

<%  
if(flag==1)
{
    Connection con1=null;
    Statement sql1=null;
    ResultSet rs1=null;
    ResultSet rs2=null;
    int flag1=1;
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       }
    catch(ClassNotFoundException e){}
    try {  con1=DriverManager.getConnection("jdbc:odbc:mis");
         sql1=con1.createStatement();
         String condition2="SELECT cname FROM customer WHERE custid = "+x;
         rs2=sql1.executeQuery(condition2);
         if(!rs2.next())
              {
       out.print("该用户不存在,2秒后返回重新操作");   
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=sample.jsp>");   
                 flag1=0;
              }
              con1.close();
         }
   catch(SQLException e1) {}

 %>
 <% 

    String t="0";
    String p="2005-9-12";
    String q="0";
    String j="2005-7-12";
    String k="0";
    if(flag1==1)
    {                  
    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=
       "INSERT INTO psample VALUES "+"("+x+",'"+sno+"','"+mDateTime+"','"+s+"','"+newpcode+"','"+newcno+"','"+newopt+"','"+t+"','"+newnote+"')";
       sql.executeUpdate(condition);
       out.print("新增客户试样完成,2秒后返回试样页面");   
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=psample.jsp>");   
           con.close();
           }
           catch(SQLException e1)
           {  }
     }
 }
}
}
   else
{
       out.print("请先登陆,系统将于2秒钟后自动返回登陆页面");
       out.print("<META HTTP-EQUIV=REFRESH CONTENT=2;url=admin.jsp>");          
}
     %>

</FONT>
</BODY>
</HTML>

⌨️ 快捷键说明

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