ITPub博客

首页 > 应用开发 > Java > JSP(4) - 增加客户模块

JSP(4) - 增加客户模块

原创 Java 作者:zhyuh 时间:2005-06-01 19:59:42 0 删除 编辑

分成before和after两个界面。before界面用于让用户输入顾客信息,after界面用于后台处理。

要点

1)jsp中引入java类

<%@ page language="java" import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>

2)得到系统当前时间,并自定义格式显示在网页中

<% Date d = new Date();
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE); %>

......

    最后修改日起:

    
3)在网页之间传递数据

before页: 

 

after页接收数据:<%String sCustID = request.getParameter("cust_id"); %>

变量sCustID就得到了上页文本框cust_id中的值

4)数据提交后将submit键灰掉

 

[@more@]

add_cust_bef.jsp

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader("Expires", 0); //prevents caching at the proxy server

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Date d = new Date();
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);
%>


 
   
   
    增加客户信息
   
   
   
   
   
   
       
    <!--
   
    -->
 
 
 
   

增加客户


   

客户卡号:     

    客户姓名:     

    性别:        
                                                        

    出生年月:     
   

    通讯地址:     

    邮政编码:     
  
    办公室电话:   
 
    家庭电话:     
  
    手机:         
 
    Email:        

    折扣:         %
   
    累计购物金额:

    增加日期:     
       
    最后修改日起:

     
   

           




  

 
 

add_cust_aft.jsp

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>


增加客户信息


<%
String sCustID = request.getParameter("cust_id");
String sCustName = request.getParameter("cust_name");
String sCustSex = request.getParameter("cust_sex");
String sCustYear = request.getParameter("cust_year");
String sCustMonth = request.getParameter("cust_month");
String sCustAddr = request.getParameter("cust_addr");
String sCustZip = request.getParameter("cust_zip");
String sCustPhOff = request.getParameter("cust_ph_office");
String sCustPhHom = request.getParameter("cust_ph_home");
String sCustMob = request.getParameter("cust_mobile");
String sCustEmail = request.getParameter("cust_email");
Float  fCustDis = Float.valueOf(request.getParameter("cust_discount"));
Float  fCustTtSum = Float.valueOf(request.getParameter("cust_trd_sum"));
String dCustAdd = request.getParameter("cust_crt_date");   
String dCustUpt = request.getParameter("cust_upt_date");

String sCustID2 = new String(sCustID.getBytes("iso-8859-1"),"GBK");
String sCustName2 = new String(sCustName.getBytes("iso-8859-1"),"GBK");
String sCustAddr2 = new String(sCustAddr.getBytes("iso-8859-1"),"GBK");
String sCustPhOff2 = new String(sCustPhOff.getBytes("iso-8859-1"),"GBK");
String sCustPhHom2 = new String(sCustPhHom.getBytes("iso-8859-1"),"GBK");

if (sCustID.equals("")){
 throw new Exception("客户卡号不准为空.");
}
if (sCustName.equals("")){
 throw new Exception("客户姓名不准为空");
}

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@TCSCH074.tcsgdccn.com:1521:orcl";
//orcl为你的数据库的SID
String user="store";
String password="store";
Connection conn= DriverManager.getConnection(url,user,password);
String sInsert = null;
Statement stmt = null;

try{

sInsert = "insert into customer(cst_id,cst_name,cst_sex, cst_year,cst_month,cst_address,cst_zip_code,";
sInsert = sInsert + "cst_ph_office, cst_ph_home, cst_mobile, cst_email, cst_discount, cst_trd_sum,";
sInsert = sInsert + "cst_crt_date, cst_upt_date) values('"+sCustID2+"','"+sCustName2+"','"+sCustSex+"','"+sCustYear+"','"+sCustMonth
  +"','"+sCustAddr2+"','"+sCustZip+"','"+sCustPhOff2+"','"+sCustPhHom2+"','"+sCustMob+"','"+sCustEmail+"',"+
  fCustDis+","+fCustTtSum+",to_date('"+dCustAdd+"','yyyy-mm-dd'),to_date('"+dCustUpt+"','yyyy-mm-dd'))";

stmt = conn.createStatement();
stmt.execute(sInsert);
conn.commit();
out.println("增加用户"+sCustName2+"完成");
}
catch(Exception e){
 System.out.println("新增用户失败!");
 e.printStackTrace();
 out.println("

新增用户失败!

");
 out.println( e.getMessage() );
 out.println("

");
}
finally{
  if(stmt != null) stmt.close();
  conn.close();
}

%>



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/207/viewspace-799591/,如需转载,请注明出处,否则将追究法律责任。

上一篇: JSP(3) - 界面框架
请登录后发表评论 登录
全部评论
  • 博文量
    233
  • 访问量
    2009583