基于javaweb+mysql的jsp+servlet电影票售票管理系统(java+jsp+servlet+javabean+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
后台:管理用户、影片、排片、影厅、订单、影评等
前台:注册登录、查看排片、详情,选座、购票等
后台
前台
技术框架
JSP Servlet MySQL C3P0 DBUtil Tomcat JavaScript CSS
基于javaweb+mysql的JSP+Servlet电影票售票管理系统(java+jsp+servlet+javabean+mysql)
private void doAddMovie(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!ServletFileUpload.isMultipartContent(req)) {
req.setAttribute("add", true);
req.getRequestDispatcher("/admin/add_update_movie.jsp").forward(req, resp);
} else {
addOrUpdateMovie(true, req, resp);
}
}
private void addOrUpdateMovie(boolean add, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//用来存参数
Map<String, String> map = new HashMap<>();
//上传图片
String uploadPath = getServletContext().getRealPath(GetImageServlet.IMG_SERVLET_DIR);
String tempPath = getServletContext().getRealPath("/WEB-INF/temp");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024 * 100);
factory.setRepository(new File(tempPath));
ServletFileUpload upload = new ServletFileUpload(factory);
String fileName = null;
try {
if (!ServletFileUpload.isMultipartContent(req)) {
throw new MyException("请使用正确的表单");
}
upload.setFileSizeMax(1024 * 1024 * 3);
upload.setHeaderEncoding("utf-8");
List<FileItem> list = upload.parseRequest(req);
for (FileItem item : list) {
//普通字段
if (item.isFormField()) {
map.put(item.getFieldName(), item.getString("utf-8"));
} else {
String realName = FileUtils.getFileName(item.getName());
if (realName == null || "".equals(realName)) {
continue;
}
fileName = Utils.generateImgFileName(realName);
File f = new File(uploadPath);
if (!f.exists()) {
f.mkdirs();
}
File file = new File(f, fileName);
/**
* 功能: 排片管理
*/
@WebServlet(urlPatterns = {"/admin/plans", "/admin/plans/add", "/admin/plans/cancel"})
public class PlanMgrServlet extends BaseServlet {
private static final long serialVersionUID = -6874708411049815744L;
private PlanService planService = BaseFactory.getService(PlanService.class);
private HallService hallService = BaseFactory.getService(HallService.class);
private MoviceService moviceService = BaseFactory.getService(MoviceService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String servletPath = req.getServletPath();
if (servletPath.contains("cancel")) {//取消排片
doDel(req, resp);
} else if (servletPath.contains("add")) {//执行添加
doAdd(req, resp);
} else {
String keyword = req.getParameter("keyword");
if (Utils.isEmpty(keyword)) {
backListToPlansJsp(planService.queryAll(), req, resp);
} else {
req.setAttribute("keyword", keyword);
backListToPlansJsp(planService.queryPlansByKeyword(keyword), req, resp);
}
}
}
private void doDel(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String planInfo = req.getParameter("plan");
if (planInfo != null) {
//从数据库删除
String[] ss = planInfo.split("_");
planService.delete(ss[0], ss[1], ss[2]);
}
resp.sendRedirect(req.getContextPath() + "/admin/plans");
}
private void doAdd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName != null) {
Movie movie = moviceService.queryByName(movieName);
if (movie != null) {
req.setAttribute("movie_name", movie.name);
} else {
resp.sendRedirect(req.getContextPath() + "/admin/movies");
return;
Utils.fillAttr(req, hall);
forwardToHallsJsp(req, resp);
}
}
private void doDel(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String hallName = req.getParameter("hall");
//如果带id参数,则是删除此影厅
if (hallName != null) {
service.deleteByName(hallName);
}
resp.sendRedirect(req.getContextPath() + "/admin/halls");
}
}
/**
* 功能: 影片详情
*/
@WebServlet(urlPatterns = "/movie/detail")
public class MovieDetailServlet extends BaseServlet {
private static final long serialVersionUID = -4869371109392125427L;
private MoviceService moviceService = BaseFactory.getService(MoviceService.class);
private EvaluateService evaluateService = BaseFactory.getService(EvaluateService.class);
private ReplyService replyService = BaseFactory.getService(ReplyService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName == null) {
String lookMovie = (String) req.getSession().getAttribute("lookMovie");
if (lookMovie == null) {
resp.sendRedirect(req.getContextPath() + "/home");
/**
* 描述:
*/
@WebServlet(urlPatterns = "/sessions")
public class MovieSessionServlet extends BaseServlet {
private static final long serialVersionUID = 8082316534539662567L;
private PlanService planService = BaseFactory.getService(PlanService.class);
private HallService hallService = BaseFactory.getService(HallService.class);
private MoviceService moviceService = BaseFactory.getService(MoviceService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (Utils.isEmpty(movieName)) {
resp.sendRedirect(req.getContextPath() + "/");
} else {
Movie movie = moviceService.queryByName(movieName);
if (movie == null) {
resp.sendRedirect(req.getContextPath() + "/");
} else {
List<Plan> plans = planService.queryNotPlayPlansByMovieName(movie.name);
if (plans != null && !plans.isEmpty()) {
List<MovieSession> sessions = new ArrayList<>();
for (Plan plan : plans) {
MovieSession ms = new MovieSession();
ms.planInfo = String.format("%s_%s_%d", plan.movie_name, plan.hall_name, plan.play_time);
ms.date = DateUtils.formatDate(plan.play_time, "yyyy-MM-dd");
ms.time = DateUtils.formatDate(plan.play_time, "HH:mm");
long overTime = plan.play_time + movie.duration * 60000;
if (!DateUtils.isSame(Calendar.DATE, plan.play_time, overTime)) {
ms.overTime = "次日" + DateUtils.formatDate(overTime, "HH:mm");
} else {
ms.overTime = DateUtils.formatDate(overTime, "HH:mm");
}
ms.price = plan.price;
ms.hallName = plan.hall_name;
Hall hall = hallService.queryByName(plan.hall_name);
* 功能: 用户登录
*/
@WebServlet(urlPatterns = "/login")
public class LoginServlet extends BaseServlet {
private static final long serialVersionUID = 8264050085226713309L;
private UserService service = BaseFactory.getService(UserService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
//带了登录界面的上级url的话,回到这个url,否则转到主页
String from = req.getParameter("from");
if (from != null) {
req.setAttribute("from", from);
}
if (username == null || password == null) {
req.getRequestDispatcher("/login.jsp").forward(req, resp);
} else {
try {
User user = service.valicateUser(username, password);
//检查验证码是否正确
String valicateCode = req.getParameter("valicateCode");
HttpSession session = req.getSession();
String sessionValicateCode = (String) session.getAttribute("valicateCode");
if (valicateCode == null || !valicateCode.equalsIgnoreCase(sessionValicateCode)) {
throw new MyException("验证码不正确");
}
req.getSession().setAttribute("user", user);
req.getSession().setMaxInactiveInterval(7200);
if (from == null) {
resp.sendRedirect(req.getContextPath() + "/");
} else {
resp.sendRedirect(req.getContextPath() + from);
}
} catch (MyException e) {
req.setAttribute("msg", e.getMessage());
Utils.fillAttr(req, "username", username);
Utils.fillAttr(req, "password", password);
req.getRequestDispatcher("/login.jsp").forward(req, resp);
}
}
}
/**
* 功能: 影片详情
*/
@WebServlet(urlPatterns = "/movie/detail")
public class MovieDetailServlet extends BaseServlet {
private static final long serialVersionUID = -4869371109392125427L;
private MoviceService moviceService = BaseFactory.getService(MoviceService.class);
private EvaluateService evaluateService = BaseFactory.getService(EvaluateService.class);
private ReplyService replyService = BaseFactory.getService(ReplyService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName == null) {
String lookMovie = (String) req.getSession().getAttribute("lookMovie");
if (lookMovie == null) {
resp.sendRedirect(req.getContextPath() + "/home");
} else {
back(req, resp, lookMovie);
}
} else {
back(req, resp, movieName);
}
}
private void back(HttpServletRequest req, HttpServletResponse resp, String movieName) throws IOException, ServletException {
Movie movie = moviceService.queryByName(movieName);
if (movie == null) {
resp.sendRedirect(req.getContextPath() + "/home");
} else {
req.getSession().setAttribute("lookMovie", movieName);
//返回影片信息及该影片的评价、回复
req.setAttribute("movie", movie);
/**
* 功能: 用户注册
*/
@WebServlet(urlPatterns = "/reg")
public class RegisterServlet extends BaseServlet {
private static final long serialVersionUID = -6923825645904193768L;
private UserService service = BaseFactory.getService(UserService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getParameterMap().isEmpty()) {
req.getRequestDispatcher("/register.jsp").forward(req, resp);
} else {
User user = new User();
String confirmPwd = req.getParameter("confirmPwd");
try {
Utils.populateToBean(user, req.getParameterMap());
//检查验证码是否正确
String valicateCode = req.getParameter("valicateCode");
HttpSession session = req.getSession();
String sessionValicateCode = (String) session.getAttribute("valicateCode");
if (valicateCode == null || !valicateCode.equalsIgnoreCase(sessionValicateCode)) {
backError(req, resp, user, confirmPwd, "验证码不正确");
return;
}
//检查信息并存到数据库
user = service.registerUser(user, confirmPwd);
//将用户添加到session
session.setAttribute("user", user);
//重定向回主页
resp.sendRedirect(req.getContextPath() + "/");
} catch (MyException e) {
backError(req, resp, user, confirmPwd, e.getMessage());
}
}
}
private void backError(HttpServletRequest req, HttpServletResponse resp, User user, String confirmPwd, String msg) throws ServletException, IOException {
req.setAttribute("msg", msg);
req.setAttribute("regUser", user);
Utils.fillAttr(req, "confirmPwd", confirmPwd);
req.getRequestDispatcher("/register.jsp").forward(req, resp);
}
}
/**
* 描述: 写影评
*/
@WebServlet(urlPatterns = "/evaluate")
public class WriteEvaluateServlet extends BaseServlet {
private static final long serialVersionUID = -3514964050010797273L;
private EvaluateService evaluateService = BaseFactory.getService(EvaluateService.class);
private MoviceService moviceService = BaseFactory.getService(MoviceService.class);
private ReplyService replyService = BaseFactory.getService(ReplyService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName == null) {
resp.sendRedirect(req.getContextPath() + "/");
} else {
Movie movie = moviceService.queryByName(movieName);
String evaId = req.getParameter("eva_id");
User user = (User) req.getSession().getAttribute("user");
if (movie == null || evaId == null) {
resp.sendRedirect(req.getContextPath() + "/");
} else if (!evaId.isEmpty()) {
//检查提交的是否相符
Evaluate eva = evaluateService.query(evaId);
if (eva != null) {
String content = req.getParameter("evaluate_content");
//截取回复内容里的昵称
Pattern pattern = Pattern.compile("\\[回复\\].+\\[/回复\\]");
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
String temp = matcher.group();
String nick = temp.replace("[回复]", "")
.replace("[/回复]", "");
if (eva.nickname.equals(nick)) {
Reply reply = new Reply();
reply.username = user.username;
reply.nickname = user.nickname;
reply.evaluate_id = Integer.valueOf(evaId);
reply.time = System.currentTimeMillis();
reply.content = content.substring(temp.length()).trim();
replyService.add(reply);
req.getSession().setAttribute("lookMovie", movie.name);
resp.sendRedirect(req.getContextPath() + "/movie/detail");
String evaluateInfo = req.getParameter("i");
if (evaluateInfo != null) {
String[] ss = evaluateInfo.split("_");
evaluateService.delete(ss[0], ss[1], ss[2]);
}
resp.sendRedirect(req.getContextPath() + "/admin/evaluates");
}
private void forwardToEvaluatesJsp(List<Evaluate> list, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
fillEvaMap(list, req, replyService);
req.setAttribute("chkItem", 5);
req.getRequestDispatcher("/admin/evaluates.jsp").forward(req, resp);
}
public static void fillEvaMap(List<Evaluate> list, HttpServletRequest req, ReplyService replyService) {
if (list != null) {
LinkedHashMap<Evaluate, List<Reply>> map = new LinkedHashMap<>();
for (Evaluate eva : list) {
List<Reply> li = replyService.queryByEvaluateId(eva.id);
map.put(eva, li == null ? new ArrayList<>() : li);
}
req.setAttribute("evamap", map);
}
}
}
/**
* 描述:选座
*/
try {
if (!ServletFileUpload.isMultipartContent(req)) {
throw new MyException("请使用正确的表单");
}
upload.setFileSizeMax(1024 * 1024 * 3);
upload.setHeaderEncoding("utf-8");
List<FileItem> list = upload.parseRequest(req);
for (FileItem item : list) {
//普通字段
if (item.isFormField()) {
map.put(item.getFieldName(), item.getString("utf-8"));
} else {
String realName = FileUtils.getFileName(item.getName());
if (realName == null || "".equals(realName)) {
continue;
}
fileName = Utils.generateImgFileName(realName);
File f = new File(uploadPath);
if (!f.exists()) {
f.mkdirs();
}
File file = new File(f, fileName);
InputStream in = item.getInputStream();
PicUtils.resizeByHeight(in, file, 300);
IOUtils.close(in);
item.delete();
}
}
Movie movie = new Movie();
Utils.populateToBean(movie, map);
//校验参数有效性
service.valicateMovie(movie);
movie.pic_name = fileName;
if (add) {
service.addMovie(movie);
} else {
//如果修改了图片,把原来的图片删除
Movie m = service.updateMovie(movie);
//修改失败删除图片
if (m == null) {
if (fileName != null) {
new File(uploadPath, fileName).delete();
/**
* 功能: 排片管理
*/
@WebServlet(urlPatterns = {"/admin/plans", "/admin/plans/add", "/admin/plans/cancel"})
public class PlanMgrServlet extends BaseServlet {
private static final long serialVersionUID = -6874708411049815744L;
private PlanService planService = BaseFactory.getService(PlanService.class);
private HallService hallService = BaseFactory.getService(HallService.class);
private MoviceService moviceService = BaseFactory.getService(MoviceService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String servletPath = req.getServletPath();
if (servletPath.contains("cancel")) {//取消排片
doDel(req, resp);
} else if (servletPath.contains("add")) {//执行添加
doAdd(req, resp);
} else {
String keyword = req.getParameter("keyword");
if (Utils.isEmpty(keyword)) {
backListToPlansJsp(planService.queryAll(), req, resp);
} else {
req.setAttribute("keyword", keyword);
backListToPlansJsp(planService.queryPlansByKeyword(keyword), req, resp);
}
}
}
private void doDel(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String planInfo = req.getParameter("plan");
if (planInfo != null) {
backListToPlansJsp(planService.queryPlansByKeyword(keyword), req, resp);
}
}
}
private void doDel(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String planInfo = req.getParameter("plan");
if (planInfo != null) {
//从数据库删除
String[] ss = planInfo.split("_");
planService.delete(ss[0], ss[1], ss[2]);
}
resp.sendRedirect(req.getContextPath() + "/admin/plans");
}
private void doAdd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName != null) {
Movie movie = moviceService.queryByName(movieName);
if (movie != null) {
req.setAttribute("movie_name", movie.name);
} else {
resp.sendRedirect(req.getContextPath() + "/admin/movies");
return;
}
} else {
Plan plan = new Plan();
Utils.populateToBean(plan, req.getParameterMap());
try {
planService.add(plan);
req.setAttribute("success", true);
} catch (MyException e) {
req.setAttribute("msg", e.getMessage());
Utils.fillAttr(req, plan);
}
}
//查询所有影厅,并返回
List<Hall> list = hallService.queryAll();
if (list != null) {
req.setAttribute("halls", list);
}
req.getRequestDispatcher("/admin/plan_movie.jsp").forward(req, resp);
}
private void backListToPlansJsp(List<Plan> list, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (list != null) {
req.setAttribute("plans", list);
}
/**
* 功能: 用户登录
*/
@WebServlet(urlPatterns = "/login")
public class LoginServlet extends BaseServlet {
private static final long serialVersionUID = 8264050085226713309L;
private UserService service = BaseFactory.getService(UserService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
//带了登录界面的上级url的话,回到这个url,否则转到主页
String from = req.getParameter("from");
if (from != null) {
req.setAttribute("from", from);
}
if (username == null || password == null) {
req.getRequestDispatcher("/login.jsp").forward(req, resp);
} else {
try {
User user = service.valicateUser(username, password);
//检查验证码是否正确
String valicateCode = req.getParameter("valicateCode");
HttpSession session = req.getSession();
String sessionValicateCode = (String) session.getAttribute("valicateCode");
if (valicateCode == null || !valicateCode.equalsIgnoreCase(sessionValicateCode)) {
throw new MyException("验证码不正确");
}
req.getSession().setAttribute("user", user);
req.getSession().setMaxInactiveInterval(7200);
if (from == null) {
resp.sendRedirect(req.getContextPath() + "/");
} else {
public class UserTicketServlet extends BaseServlet {
private static final long serialVersionUID = 8056006200411003099L;
private OrderService orderService = BaseFactory.getService(OrderService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
forwardToOrderJsp(req, resp);
}
private List<Ticket> getTicketList(String userId) {
List<Ticket> list = new ArrayList<>();
List<Order> orders = orderService.queryUserOrders(userId);
if (orders != null) {
for (Order order : orders) {
Ticket ticket = getTicket(order);
if (ticket != null) {
list.add(ticket);
}
}
}
return list;
}
public static Ticket getTicket(Order order) {
PlanService planService = BaseFactory.getService(PlanService.class);
Plan plan = planService.query(String.valueOf(order.plan_id));
if (plan != null) {
MoviceService moviceService = BaseFactory.getService(MoviceService.class);
Movie movie = moviceService.queryByName(plan.movie_name);
HallService hallService = BaseFactory.getService(HallService.class);
Hall hall = hallService.queryByName(plan.hall_name);
if (movie != null && hall != null) {
Ticket ticket = new Ticket();
ticket.orderId = order.id;
ticket.buyTime = DateUtils.formatDate(order.create_time, "yyyy-MM-dd HH:mm");
ticket.movieName = plan.movie_name;
ticket.picName = movie.pic_name;
ticket.hallName = plan.hall_name;
ticket.playTime = DateUtils.formatDate(plan.play_time, "yyyy-MM-dd HH:mm");
ticket.endTime = DateUtils.formatDate(plan.play_time + movie.duration * 60000, "HH:mm");
ticket.language = movie.language;
ticket.hallType = hall.type;
ticket.seats = new ArrayList<>();
String[] ss = order.seat.split("\\|");
for (String s : ss) {
if (s.matches("\\d+_\\d+")) {
String[] split = s.split("_");
ticket.seats.add(split[0] + "排" + split[1] + "座");
}
for (int i = 1; i <= hall.rows; i++) {
List<Seat> seats = new ArrayList<>();
for (int j = 1; j <= hall.columns; j++) {
Seat seat = new Seat();
seat.seat = i + "_" + j;
seat.sold = orderService.isSeatSold(String.valueOf(plan.id), seat.seat);
seats.add(seat);
}
rowSeats.add(seats);
}
req.setAttribute("price", plan.price);
req.setAttribute("session", session);
req.setAttribute("seats", rowSeats);
req.setAttribute("title", String.format("%s(%s %s)", plan.movie_name, hall.type, DateUtils.formatDate(plan.play_time, "yyyy-MM-dd HH:mm")));
req.getRequestDispatcher("/seat.jsp").forward(req, resp);
} else {
resp.sendRedirect(req.getContextPath() + "/");
}
} else {
resp.sendRedirect(req.getContextPath() + "/");
}
}
}
}
@WebServlet(urlPatterns = "/code")
public class ValicateImgServlet extends HttpServlet {
private static final long serialVersionUID = -8609971128908819964L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setIntHeader("Expires", -1);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
int width = 100;
/**
* 功能: 影片管理
*/
@WebServlet(urlPatterns = {"/admin/movies", "/admin/movies/add", "/admin/movies/update", "/admin/movies/delete"})
public class MovieMgrServlet extends BaseServlet {
private static final long serialVersionUID = 2225249275913675741L;
private MoviceService service = BaseFactory.getService(MoviceService.class);
@Override
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//根据url判断是做什么操作
String servletPath = req.getServletPath();
if (servletPath.contains("add")) {
doAddMovie(req, resp);
} else if (servletPath.contains("update")) {
doUpdateMovie(req, resp);
} else if (servletPath.contains("delete")) {
doDel(req, resp);
} else {
//如果关键字不为空,搜索返回,否则返回全部
String keyword = req.getParameter("keyword");
if (Utils.isEmpty(keyword)) {
forwardToMoviesJsp(service.queryAll(), req, resp);
} else {
req.setAttribute("keyword", keyword);
private void doDel(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName != null) {
Movie movie = service.deleteByName(movieName);
//删除成功的话,把原图片一起删除
if (movie != null) {
new File(getServletContext().getRealPath(GetImageServlet.IMG_SERVLET_DIR), movie.pic_name).delete();
}
}
forwardToMoviesJsp(service.queryAll(), req, resp);
}
private void doUpdateMovie(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String movieName = req.getParameter("movie");
if (movieName != null) {
//查询到则返回,没有则返回影片管理
Movie movie = service.queryByName(movieName);
if (movie == null) {
forwardToMoviesJsp(service.queryAll(), req, resp);
} else {
Utils.fillAttr(req, movie);
req.setAttribute("add", false);
req.getRequestDispatcher("/admin/add_update_movie.jsp").forward(req, resp);
}
} else {
addOrUpdateMovie(false, req, resp);
}
}
private void doAddMovie(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!ServletFileUpload.isMultipartContent(req)) {
req.setAttribute("add", true);
req.getRequestDispatcher("/admin/add_update_movie.jsp").forward(req, resp);
} else {
addOrUpdateMovie(true, req, resp);
}
}
private void addOrUpdateMovie(boolean add, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//用来存参数
Map<String, String> map = new HashMap<>();
//上传图片
String uploadPath = getServletContext().getRealPath(GetImageServlet.IMG_SERVLET_DIR);
String tempPath = getServletContext().getRealPath("/WEB-INF/temp");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024 * 100);
factory.setRepository(new File(tempPath));
ServletFileUpload upload = new ServletFileUpload(factory);
String fileName = null;
try {
if (!ServletFileUpload.isMultipartContent(req)) {