📄 customerservlet.java
字号:
package com.mobile.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mobile.bean.TAccount;
import com.mobile.bean.TCustomer;
import com.mobile.bean.TUser;
import com.mobile.dao.AccountDAO;
import com.mobile.dao.CustmerDAO;
import com.mobile.dao.UserDAO;
public class CustomerServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public CustomerServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
System.out.println("999999999999999999999999999999");
String flag=request.getParameter("flag");
if("newAccount".equals(flag)){
System.out.println("11111111111199999999999999999999");
String Account_ID=request.getParameter("Account_ID");
String Contact_Person = request.getParameter("Contact_Person");
String Contact_Address = request.getParameter("Contact_Address");
System.out.println(Account_ID+"nnnnnnnnnnnnnnnnnnnnnn");
String money =request.getParameter("money");
TAccount ac=new TAccount();
ac.setAccount_ID(Integer.parseInt(Account_ID));
ac.setContactPerson(Contact_Person);
ac.setContactAddress(Contact_Address);
ac.setAccountBalance(Integer.parseInt(money));
AccountDAO ad=new AccountDAO();
int id= ad.addAccount(ac);
TCustomer cu=(TCustomer)request.getAttribute("user");
// request.setAttribute("user_id",Account_ID.substring(5,Account_ID.length()) );
request.setAttribute("account", ac);
request.setAttribute("user", cu);
System.out.println(cu+"el");
request.getRequestDispatcher("new_user.jsp").forward(request, response);
}
if("new_customer".equals(flag)){
CustmerDAO cd = new CustmerDAO();
String idType = (String)request.getParameter("type");
String idNumber=request.getParameter("number");
request.getSession().setAttribute("type",idType);
request.getSession().setAttribute("number",idNumber);
TCustomer customer;
customer=(TCustomer)cd.CheckCustomer(idType, idNumber);
System.out.println(customer+"11111");
if(customer==null){
response.sendRedirect("new_customer1.jsp");
}
else{
request.setAttribute("cust", customer);
request.getRequestDispatcher("new_customent.jsp").forward(request, response);
}
}
if("check_user".equals(flag)){
System.out.println("999999999999999999999999999999");
TCustomer tc=(TCustomer)request.getSession().getAttribute("user");
//TCustomer tc=(TCustomer)request.getAttribute("user");
AccountDAO ac=new AccountDAO();
System.out.println(tc.getCustomerId()+"000000000000000000000");
TAccount b=ac.checkAccountDAO(tc.getCustomerId());
System.out.println(b+"000000000000000000000");
System.out.println(tc);
if(b!=null){
request.setAttribute("account", b);
request.setAttribute("user", tc);
request.getRequestDispatcher("new_user.jsp").forward(request, response);
}
else{
request.setAttribute("user", tc);
System.out.println(tc+"el");
request.getRequestDispatcher(" new_account.jsp").forward(request, response);
}
}
if("updata_customer".equals(flag)){
TCustomer customer = new TCustomer();
CustmerDAO cd = new CustmerDAO();
String idType = (String)request.getSession().getAttribute("type");
String customerName =request.getParameter("username");
String idNumber=request.getParameter("num");
String customerBirthday = request.getParameter("birthday_year")+"-"+request.getParameter("birthday_month")+"-"+request.getParameter("birthday_day");
String customerGender = request.getParameter("sex");
System.out.println(customerGender +"ddddddddddddaa");
String customerAddress =request.getParameter("address");
customer.setIdNumber(idNumber);
customer.setCustomerName(customerName);
customer.setCustomerBirthday(customerBirthday);
customer.setCustomerGender(customerGender.charAt(0));
customer.setCustomerAddress(customerAddress);
cd.updataCustomer(customer);
request.setAttribute("cust", customer);
request.getRequestDispatcher("new_customent.jsp").forward(request, response);
}
if ("add_Customer".equals(flag))
{
TCustomer customer = new TCustomer();
CustmerDAO cd = new CustmerDAO();
String idType = (String)request.getSession().getAttribute("type");
String idType1 = "0";
System.out.println("dddddddddddddddddddddddddddddddddddddd");
if (idType.equals("居民身份证"))
idType1 = "D";
if (idType.equals("军官证"))
idType1 = "A";
if (idType.equals("护照"))
idType1 = "P";
String idNumber = (String)request.getSession().getAttribute("number");
String customerName =request.getParameter("username");
String customerBirthday = request.getParameter("birthday_year")+"-"+request.getParameter("birthday_month")+"-"+request.getParameter("birthday_day");
String customerGender = request.getParameter("sex");
System.out.println(customerGender +"ddddddddddddaa");
String customerAddress =request.getParameter("address");
customer.setIdType(idType1);
customer.setIdNumber(idNumber);
customer.setCustomerName(customerName);
customer.setCustomerBirthday(customerBirthday);
customer.setCustomerGender(customerGender.charAt(0));
customer.setCustomerAddress(customerAddress);
int ib=cd.addCustomer(customer);
customer.setCustomerId(ib);
request.setAttribute("user",customer);
request.getRequestDispatcher(" new_account.jsp").forward(request, response);
}
if ("add_user".equals(flag))
{
TUser user1 = new TUser();
String mobileNumber = request.getParameter("phone_numb");
String roamingStatus = request.getParameter("zt");
String comLevel = request.getParameter("grade");
String customerId = request.getParameter("id");
String accountId = request.getParameter("Account_ID");
user1.setMobileNumber(mobileNumber);
System.out.println(roamingStatus);
System.out.println(roamingStatus.charAt(0));
user1.setRoamingStatus(roamingStatus.charAt(0));
user1.setComLevel(comLevel.charAt(0));
user1.setCustomerId(Long.parseLong(customerId));
user1.setAccountId(Long.parseLong(accountId));
UserDAO tud = new UserDAO();
AccountDAO tad = new AccountDAO();
int ff=tud.addUser(user1);
System.out.println( ff +"tf");
System.out.println( user1.getAccountId() +"uf");
TAccount ta=tad.checkAccountDAO((int)user1.getAccountId());
System.out.println(ta+"ta");
request.setAttribute("account",ta);
request.getRequestDispatcher("account.jsp").forward(request, response);
}
if ("addAccount".equals(flag))
{
TAccount ta = new TAccount();
AccountDAO tad = new AccountDAO();
String contactPerson = request.getParameter("Account_ID");
String contactAddress = request.getParameter("Contact_Address");
String accountBalance = request.getParameter("money");
ta.setContactPerson(contactPerson);
ta.setContactAddress(contactAddress);
ta.setAccountBalance(Float.valueOf(accountBalance).floatValue());
tad.addAccount(ta);
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -