分成before和after两个界面。before界面用于让用户输入顾客信息,after界面用于后台处理。
要点
1)jsp中引入java类
2)得到系统当前时间,并自定义格式显示在网页中
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE); %>
......
最后修改日起:
3)在网页之间传递数据
before页:
after页接收数据:
变量sCustID就得到了上页文本框cust_id中的值
4)数据提交后将submit键灰掉
[@more@]add_cust_bef.jsp
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);
%>
增加客户信息
<!--
-->
增加客户
客户卡号:
客户姓名:
性别: 男
女
出生年月: 年
for (int i=10;i<12;i++) {
%>
月
通讯地址:
邮政编码:
办公室电话:
家庭电话:
手机:
Email:
折扣: %
累计购物金额:
增加日期:
最后修改日起:
add_cust_aft.jsp
增加客户信息
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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/207/viewspace-799591/