package Servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Dao.RentInfoDao;
import JDBC.DBUtil;
import bean.RentInfo;
/**
* Servlet implementation class RentVideo
*/
@WebServlet("/rentVideo")
public class rentVideo extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public rentVideo() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
PrintWriter out=response.getWriter();
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
int videoId=Integer.parseInt(request.getParameter("videoId"));
//String username=request.getParameter("name");
String username=(String) request.getSession().getAttribute("name");
System.out.println(videoId);
System.out.println(username);
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int result=0;
int user_id = 0;
String title = "";
int price = 0;
String expected_return_date ="";
try {
conn = DBUtil.getConn();
stmt = conn.createStatement();
String sqlstr = "select * from video where id='" + videoId + "'and state='可租赁'";
rs = stmt.executeQuery(sqlstr);
rs.next();
if (rs.getRow() != 0) {
rs.last();//对rs的操作应马上操作,操作完后再从数据库得到rs,再对rs操作
// 查询影像名称,价格
String sql = "select title,price from video where id='" + videoId + "'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
title = rs.getString(1);
// price:租金,点击租赁,租金即为影像的价格
price = rs.getInt(2);
}
// 查询用户编号
rs.last();//对rs的操作应马上操作,操作完后再从数据库得到rst,再对rst操作
sql = "select id from user where name='" + username + "'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
user_id = rs.getInt(1);
}
// 获取当前系统时间--租赁时间
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String rent_date = formatter.format(currentTime);
System.out.println("租赁时间:");
System.out.println(rent_date);
// 设置最晚归还时间,设置租借期限为10天
Calendar cal = Calendar.getInstance();
cal.setTime(currentTime);
cal.add(Calendar.DAY_OF_MONTH, 10);
Date excepted_return_time = cal.getTime();
expected_return_date = formatter.format(excepted_return_time);
System.out.println("应归还时间:");
System.out.println(expected_return_date);
// 更新影像信息表中状态为“已租赁”
sql = "update video set state='已租赁' where id=" + videoId;
stmt.executeUpdate(sql);
// 将各个参数插入到租赁信息表中
sql = "insert into rentinfo (title,user_id, video_id,rent_date,expected_return_date,return_date,state,rental)values ('"
+ title + "', '" + user_id + "', '" + videoId + "','" + rent_date + "','" + expected_return_date+ "',' ','未归还','" + price + "')";
result=stmt.executeUpdate(sql);
if (result>0) {
System.out.println("租赁影像成功!");
//out.print("<script>alert('租赁影像成功!');</script>");
//response.sendRedirect("/RentSystem/U_rentVideo.jsp");
String a = URLEncoder.encode("租赁影像成功!", "UTF-8");
out.print("<script language='javascript'>alert(decodeURIComponent('"+a+"'));window.location.href='U_rentVideo.jsp'</script>");
} else {
System.out.println("租赁失败!");
//out.print("<script>alert('租赁影像失败!');</script>");
//response.sendRedirect("/RentSystem/U_rentVideo.jsp");
String a = URLEncoder.encode("租赁影像失败,请重新选择!", "UTF-8");
out.print("<script language='javascript'>alert(decodeURIComponent('"+a+"'));window.location.href='U_rentVideo.jsp'</script>");
}
} else {
//out.print("<script>alert('该影像已租赁!');window.location.href='U_rentInformation.jsp'");
System.out.println("该影像已租赁!");
String a = URLEncoder.encode("该影像已被租赁,请选择未租赁的影像!", "UTF-8");
out.print("<script language='javascript'>alert(decodeURIComponent('"+a+"'));window.location.href='U_rentVideo.jsp'</script>");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
影像租赁管理系统(JAVAEE课程设计) (110个子文件)
rentVideo.class 5KB
UserDao.class 5KB
loginCheck.class 5KB
RentInfoDao.class 5KB
VideoDao.class 4KB
returnVideo.class 4KB
updateVIP.class 4KB
updatePassword.class 4KB
registerVIP.class 4KB
bespeakVideo.class 3KB
loginFilter.class 3KB
addVIP.class 3KB
addRentInfo.class 3KB
BespeakInfoDao.class 3KB
RentInfo.class 3KB
addVideo.class 2KB
deleteVIP.class 2KB
addBespeakInfo.class 2KB
deleteVideo.class 2KB
Video.class 2KB
ManagerDao.class 2KB
User.class 2KB
loginOut.class 2KB
DBUtil.class 2KB
BespeakInfo.class 1KB
Manager.class 1KB
.classpath 939B
org.eclipse.wst.common.component 482B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 977B
styleUser.css 976B
style_main.css 754B
mysql-connector-java-5.1.40-bin.jar 968KB
rentVideo.java 6KB
RentInfoDao.java 6KB
loginCheck.java 5KB
registerVIP.java 5KB
VideoDao.java 4KB
UserDao.java 4KB
returnVideo.java 4KB
loginFilter.java 4KB
updateVIP.java 4KB
updatePassword.java 3KB
addVIP.java 3KB
addRentInfo.java 3KB
bespeakVideo.java 3KB
addVideo.java 3KB
deleteVIP.java 2KB
addBespeakInfo.java 2KB
deleteVideo.java 2KB
RentInfo.java 2KB
BespeakInfoDao.java 2KB
ManagerDao.java 2KB
DBUtil.java 2KB
Video.java 2KB
loginOut.java 2KB
User.java 1KB
BespeakInfo.java 1KB
Manager.java 670B
bg1.jpg 1.08MB
bg1.jpg 1.08MB
bg2.jpg 1023KB
bg-1.jpg 802KB
bg5.jpg 750KB
bg_index.jpg 750KB
back4.jpg 699KB
bg5.jpg 573KB
bg4.jpg 545KB
bg3.jpg 358KB
注册.jpg 307KB
back1.jpg 192KB
背景1.jpg 188KB
back2.jpg 164KB
bg2.jpg 125KB
bg_login.jpg 125KB
back0.jpg 105KB
影片登陆2.jpg 82KB
.jsdtscope 567B
U_Register.jsp 5KB
login.jsp 4KB
rent_video_add.jsp 4KB
video_add.jsp 3KB
U_updatePassword.jsp 3KB
U_rentInformation.jsp 3KB
manager_index.jsp 3KB
rent_bespeakVideo.jsp 3KB
U_index.jsp 3KB
user_add.jsp 3KB
U_update_UserInformation.jsp 2KB
rent_getInformation.jsp 2KB
video_getInformation.jsp 2KB
U_rentVideo.jsp 2KB
U_rent_bespeakVideo.jsp 2KB
U_UserInformation.jsp 2KB
user_getInformation.jsp 2KB
rent_getBespeakInfo.jsp 2KB
rent_manage.jsp 2KB
video_manage.jsp 1KB
user_manage.jsp 1KB
contact.jsp 815B
共 110 条
- 1
- 2
资源评论
- qq_376529932020-12-30好用,推荐下载
qq_37652993
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功