Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jweb/src/com/HotelDAO/HotelDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.HotelDAO;
import javaBean.Customer;
public interface HotelDAO {
public abstract int create(Customer cus)throws Exception;
public abstract void remove(Customer cus)throws Exception;
public abstract Customer find(Customer cus)throws Exception;

}
74 changes: 74 additions & 0 deletions jweb/src/com/HotelDAO/HotelsDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.HotelDAO;
import java.sql.*;
import javaBean.db.*;
import javaBean.Customer;
public class HotelsDAO implements HotelDAO{
protected static final String FIELDS_INSERT="id,name,room,bill";
protected static String INSERT_SQL="insert into cus_info("
+FIELDS_INSERT+")"+"values(?,?,?,?)";
protected static String DELETE_SQL="delete from cus_info where id=?";
protected static String SELECT_SQL="select"
+FIELDS_INSERT+"frome cus_info where id=?";
//ʵ�������ݿ������Ӽ�¼
public int create(Customer cus)throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
int n=0;
try{
con=DbConnect.getDBconnection();
prepStmt=con.prepareStatement(INSERT_SQL);
prepStmt.setDouble(1,cus.getId());
prepStmt.setString(2, cus.getName());
prepStmt.setInt(3,cus.getRoom());
prepStmt.setFloat(4, 0);
n=prepStmt.executeUpdate();
System.out.print(cus.getName());
}catch(Exception e){
DbConnect.closeDB(con,prepStmt,rs);
}
return n;
}

//ʵ�ֲ�ѯ���ݿ��ж�ָ���ļ�¼�Ƿ����
public Customer find(Customer cus)throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
Customer cus2=null;
try{
con=DbConnect.getDBconnection();
prepStmt=con.prepareStatement(INSERT_SQL);
prepStmt.setDouble(1, cus.getId());
rs=prepStmt.executeQuery();
if(rs.next()){
cus2=new Customer();
cus2.setId(rs.getInt(1));
cus2.setName(rs.getString(2));
cus2.setRoom(rs.getInt(3));
cus2.setBill(rs.getFloat(4));
}
}catch(Exception e){

}finally{
DbConnect.closeDB(con, prepStmt, rs);
}
return cus2;
}

public void remove(Customer cus)throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
try{
con=DbConnect.getDBconnection();
prepStmt=con.prepareStatement(DELETE_SQL);
prepStmt.setDouble(1,cus.getId());
prepStmt.executeUpdate();
}catch(Exception e){

}finally{
DbConnect.closeDB(con,prepStmt,rs);
}
}
}
33 changes: 33 additions & 0 deletions jweb/src/javaBean/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package javaBean;

public class Customer {
private double id;
private String name;
private int room;
private float bill;
public double getId() {
return id;
}
public void setId(double id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRoom() {
return room;
}
public void setRoom(int room) {
this.room = room;
}
public float getBill() {
return bill;
}
public void setBill(float bill) {
this.bill = bill;
}

}
26 changes: 26 additions & 0 deletions jweb/src/javaBean/Room.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package javaBean;

public class Room {
private int number;
private String type;
private String zhuangtai;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getZhuangtai() {
return zhuangtai;
}
public void setZhuangtai(String zhuangtai) {
this.zhuangtai = zhuangtai;
}

}
32 changes: 32 additions & 0 deletions jweb/src/javaBean/db/DbConnect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package javaBean.db;
import java.sql.*;
public class DbConnect {
private static String driverName="com.mysql.jdbc.Driver";
private static String userName="root";
private static String userPwd="root";
private static String dbName="customer";
public static Connection getDBconnection(){
String url1="jdbc:mysql://localhost/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=GB2312&useSSL=false";
String url=url1+url2+url3;
try{
Class.forName(driverName);
Connection con=DriverManager.getConnection(url);
return con;
}catch(Exception e){
e.printStackTrace();
}
return null;

}
public static void closeDB(Connection con,PreparedStatement pstm,ResultSet rs){
try{
if(rs!=null)rs.close();
if(pstm!=null)pstm.close();
if(con!=null)con.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
92 changes: 92 additions & 0 deletions jweb/src/servlet/Insert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javaBean.Customer;
import com.HotelDAO.*;
import javaBean.db.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Insert extends HttpServlet {

/**
* Constructor of the object.
*/
public Insert() {
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("utf-8");
double id=Double.parseDouble(request.getParameter("id"));
String name=request.getParameter("name");
int room=Integer.parseInt(request.getParameter("room"));
Customer cus=new Customer();
int n=0;
cus.setId(id);
cus.setName(name);
cus.setRoom(room);
HotelsDAO run=new HotelsDAO();
try {
n=run.create(cus);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if(n>=1)
request.getRequestDispatcher("success.jsp").forward(request, response);
else
request.getRequestDispatcher("error.jsp").forward(request, response);
}

/**
* 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 {
doGet(request,response);
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}
85 changes: 85 additions & 0 deletions jweb/src/servlet/Se1414080902137Servlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Se1414080902137Servlet extends HttpServlet {


/**
* Constructor of the object.
*/
public Se1414080902137Servlet() {
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 {

doPost(request,response);
}

/**
* 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 {

response.setContentType("text/html");
String userName=request.getParameter("username");
String userPwd=request.getParameter("password");
String info="";
if(("abc").equals(userName)&&("123").equals(userPwd)){
info="��ӭ�㣬"+userName+"!";
request.setAttribute("a", userName);
request.setAttribute("outputMessage", info);
request.getRequestDispatcher("index.jsp").forward(request,response);
}else{
response.sendRedirect("index_title.jsp?error=yes");

}


}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}
6 changes: 3 additions & 3 deletions jweb/web/1414080902137/occupancy.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
</head>

<body>
<form action="tijiao.jsp" method="post">
身份证:<input type="text" name="idcard"><br>
<form action="Insert" method="post">
身份证:<input type="text" name="id"><br>
姓名:<input type="text" name="name"><br>
房间号:<input type="text" name="number"><br>
房间号:<input type="text" name="room"><br>
<input type="submit" value="确定">

</form>
Expand Down
7 changes: 4 additions & 3 deletions jweb/web/1414080902137/tijiao.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
</head>

<body>
<c:out value="${param.idcard}" default="cuowu1"/>
<c:out value="${param.name}" default="cuowu2"/>
<c:out value="${param.number}"default="cuowu3"/>
<div>确认信息</div>
客户身份证:<%=request.getParameter("id") %>
客户姓名:<%=request.getParameter("name") %>
房间号:<%=request.getParameter("room") %>
</body>
</html>