/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author LandE
*/
public class login extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
String userName = "";
String password = "";
PrintWriter out = response.getWriter();
Cookie[] cookies = request.getCookies();
if(cookies != null)
{
for(int i =0;i <cookies.length;i++)
{
if(cookies[i].getName().equals("userName"))
{
userName = cookies[i].getValue();
}
if(cookies[i].getName().equals("password"))
{
password = cookies[i].getValue();
}
}
}
out.println("<title>网页聊天系统</title>");
out.println("<meta charset=\"gbk\">");
out.println("<meta name=\"viewport\" content=\"width=device-width\">");
out.println("</head>");
out.println("<body background='11.jpg'>");
out.println("<h1 align=\"center\"> </h1><h1 align=\"center\"><b>欢迎登陆聊天室</b></h1>");
out.println("<form name=\"login\" action=\"Main\" method =\"post\">");
out.println("<table width=\"52%\" border=\"2\" align=\"center\">");
out.println("<tr bgcolor=\"#C1FFC1\">");
out.println("<td align=\"center\" width=\"43%\"> <div align=\"center\">用户名:</div></td>");
out.println("<td width=\"57%\"> <div align=\"left\">");
out.println("<input type=\"text\" name=\"username\" value =\""+userName+"\">");
out.println("</div></td>");
out.println("</tr>");
out.println("<tr bgcolor=\"#C1FFC1\">");
out.println("<td align=\"center\" width=\"43%\"> <div align=\"center\">密 码:</div></td>");
out.println("<td width=\"57%\"> <div align=\"left\">");
out.println("<input type=\"password\" name=\"password\" value =\""+password+"\">");
out.println("</div></td>");
out.println("</tr>");
out.println("</table>");
out.println("<p align=\"center\">");
out.println("<input type=\"checkbox\" name=\"checkbox\" value=\"yes\">记住密码");
out.println("<input type=\"submit\" name=\"Submit2\" value=\"提交\">");
out.println("<input type=\"reset\" name=\"Reset\" value=\"重置\">");
out.println("</p>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}