package com.kk.contrall;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import javax.servlet.ServletContext;
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 javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
import com.kk.doma.Order;
import com.kk.doma.User;
import com.kk.servic.OrderServic;
/**
* Servlet implementation class ShouYeClServlet
*/
@WebServlet("/ShouYeClServlet")
public class ShouYeClServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ShouYeClServlet() {
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
request.setCharacterEncoding("utf-8");
response.setContentType("text/html ;charset=utf-8");
PrintWriter out = response.getWriter();
//接收首页传过来的信息
String login = request.getParameter("login");
String zhuCe = request.getParameter("zhuce");
String vipname = request.getParameter("vipname");
String type = request.getParameter("type");
String adminlogin = request.getParameter("adminlogin");
System.out.println(login);
System.out.println("type="+type);
System.out.println("会员名称="+vipname);
System.out.println("管理员登录="+adminlogin);
//String reYing = request.getParameter("login");
//String shangYing = request.getParameter("login");
if(login != null ) {
if(("登录").equals(login)) {
request.getRequestDispatcher("WEB-INF/Login.jsp").forward(request, response);
}
}else if(zhuCe != null ) { //思路:注册成功后让用户重新登录(这个功能还没实现)
if(("注册").equals(zhuCe)){
request.getRequestDispatcher("WEB-INF/Zhuce.jsp").forward(request, response);
}
}else if(adminlogin != null) { //管理员登录"管理员登录".equals(adminlogin)
if("管理员登录".equals(adminlogin)) {
request.getRequestDispatcher("WEB-INF/AdminLogin.jsp").forward(request, response);
}
}else if(vipname != null) { //在这里判断是否登录
HttpSession session = request.getSession();
if((User)session.getAttribute("loginUser") !=null){ //判断是否登
//应该在这里准备数据
//从Session取出用户名
//从数据库取出订单信息
OrderServic orderServic = new OrderServic();
ArrayList al = orderServic.getOdersDetail(vipname);
Order order = null;
for(int i=0;i<al.size();i++) {
order = (Order)al.get(i);
}
request.getSession().setAttribute("showmyOrder", order); //把登录信息存在Session中
String MoviceName = ((Order)session.getAttribute("showmyOrder")).getMoviceName();
request.getRequestDispatcher("WEB-INF/VipCenter.jsp").forward(request, response);
}else{ //没有登录转到登录界面
System.out.println("有空值");
request.getRequestDispatcher("WEB-INF/Login.jsp").forward(request, response);
}
}else if("exitG".equals(type)) {
}else if(type.equals("fastBuyTicks")) { //闪电购票
System.out.println("//闪电购票");
//先判断是否登录,从Session中取出登录信息
HttpSession session = request.getSession();
System.out.println("session="+session);
User user = new User();
if((User)session.getAttribute("loginUser") !=null){ //判断是登录le
System.out.println("已经登录");
//已经登录就直接跳转首页(将来要做一个提示窗口:你已经登录)
String i = request.getParameter("id");
System.out.println("i="+i);
int i1 = Integer.parseInt(i);
if(i1%2==0) {
String block="none";
request.setAttribute("none", block);
}else {
String block = "block";
request.setAttribute("block", block);
}
i1++;
System.out.println("i1="+i1);
request.setAttribute("i", i1+"");
request.getRequestDispatcher("WEB-INF/ShouYe.jsp").forward(request, response);
}else{ //没有登录就继续登录
//转到登录界面
request.getRequestDispatcher("WEB-INF/Login.jsp").forward(request, response);
}
}
}
/**
* @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);
}
}