院系:计算机科学学院专业:年级:课程名称:组号:姓名(学号):指导教师:2015年月日2.登录界面和聊天登录输入:需要编码语言格式,将输入的内容转换成中文:6.会话输入及显示:String message=request.getParameter("message");try (PrintWriter out = response.getWriter()) {Login.jsp:<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><%Cookie[] cookies =request.getCookies();String user1="",password1="";if(cookies !=null){for(int i=0;i<cookies.length;i++){if(cookies[i].getName().equals("username")){user1=cookies[i].getValue();user1=.URLDecoder.decode(user1,"UTF-8");request.getSession().setAttribute("user", user1);};if(cookies[i].getName().equals("password")){password1=cookies[i].getValue();password1=.URLDecoder.decode(password1,"UTF-8");request.getSession().setAttribute("password", password1);}}}%><body><form action="Main" name="login" method="post"><table width="52%" border="2" align="center"><h1 align="center"><b>欢迎登陆聊天室</b></h1><tr bgcolor="#FFFFCC"><td align="center" width="43%"><div align="center">用户名:</div></td> <td width="57%"> <div align="left"><input type="text" name="userID" value="${user}"> </div></td> </tr><tr bgcolor="#FFFFCC"><td align="center" width="43%"><div align="center">密码:</div></td><td width="57%"><div align="left"> <input type="password" name="password" value="${password}"> </div></td> </tr></table><p align="center"><input type="checkbox" name="remember" value="yes" />记住用户名和密码<input type="submit" name="tj" value="提交"><input type="reset" name="reset"></p></form></body></html>Main.javapackage com.login;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class Main extends HttpServlet {protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");try (PrintWriter out = response.getWriter()) {String userID=request.getParameter("userID");if(userID==null)userID="";String password=request.getParameter("password");if(password==null)password="";String remember=request.getParameter("remember");HttpSession session = request.getSession(true);if((userID.equals("纳洪泽")&&password.equals("1"))||(userID.equals("司少武")&&password.equals("2"))||(userID.equals("张宇")&&password.equals("3"))){session.setAttribute("user",userID);//保存名字到sessionif(remember!=null&&remember.equals("yes")){userID=.URLEncoder.encode(userID,"UTF-8");password=.URLEncoder.encode(password,"UTF-8");int maxAge = 10000;Cookie usernameCookie=new Cookie("username",userID);Cookie passwordCookie=new Cookie("password",password);usernameCookie.setPath(request.getContextPath());passwordCookie.setPath(request.getContextPath());usernameCookie.setMaxAge(maxAge);passwordCookie.setMaxAge(maxAge);response.addCookie(usernameCookie);response.addCookie(passwordCookie);}RequestDispatcher dispatcher=request.getRequestDispatcher("LoginSuccess");dispatcher.forward(request,response);}else{RequestDispatcher dispatcher=request.getRequestDispatcher("LoginFail");dispatcher.forward(request,response);}}}NEWlogin.javapackage com.login;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@WebServlet(name = "NEWlogin", urlPatterns = {"/NEWlogin"})public class NEWlogin extends HttpServlet {protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html;charset=UTF-8");try (PrintWriter out = response.getWriter()) {/* TODO output your page here. You may use following sample code. */out.println("<!DOCTYPE html>");out.println("<html>");out.println("<head>");out.println("<title>Servlet NEWlogin</title>");out.println("</head>");out.println("<frameset cols=36%,*>");out.println("<frame src=\"chatLog\" noresize=\"noresize\">");out.println("<frame src=\"Login.jsp\" noresize=\"noresize\">");out.println("<body>");out.println("</body>");out.println("</html>");}}LoginSuccess.javapackage com.login;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class LoginSuccess extends HttpServlet {protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");try (PrintWriter out = response.getWriter()) {/* TODO output your page here. You may use following sample code. */String name=request.getParameter("userID");out.println("<!DOCTYPE html>");out.println("<html>");out.println("<head>");out.println("<title>您已登录聊天窗口</title>");out.println("</head>");out.println("<frameset cols=100%,*>");out.println("<frame src=\"sendMessage\">");out.println("</frameset>");out.println("</html>");out.close();}}LoginFail.javapackage com.login;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class LoginFail extends HttpServlet {protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");try (PrintWriter out = response.getWriter()) {/* TODO output your page here. You may use following sample code. */out.println("<!DOCTYPE html>");out.println("<html>");out.println("<head>");out.println("<title>登录失败</title>");out.println("</head>");out.println("<body>");out.println("<center><h1>信息错误请重新登陆</h1></center>");RequestDispatcher dispatcher=request.getRequestDispatcher("Login.jsp");dispatcher.include(request,response);out.println("</body>");out.println("</html>");out.close();}}chatLog.javapackage com.login;import java.io.IOException;import java.io.PrintWriter;import static ng.System.out;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class chatLog extends HttpServlet {protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");String recordList=( String) getServletContext().getAttribute("recordList");if(recordList==null){recordList="";}response.setHeader("Refresh", "1");try (PrintWriter out = response.getWriter()) {/* TODO output your page here. You may use following sample code. *///String message=request.getParameter("message");out.println("<!DOCTYPE html>");out.println("<html>");out.println("<head>");out.println("<title>Servlet chatLog</title>");out.println("</head>");out.println("<body>");out.println("<h4><i><color=DarkOrchid>聊天记录</color></i></h4>");out.println("<div >" + recordList + "</div> ");out.println("</body>");out.println("</html>");}}private List ArrayList() {throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.}}sendMessagepackage com.login;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class sendMessage extends HttpServlet {protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {HttpSession session = request.getSession(true);request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");String message=request.getParameter("message");try (PrintWriter out = response.getWriter()) {/* TODO output your page here. You may use following sample code. */String username=(String)session.getAttribute("user");String recordList=(String) getServletContext().getAttribute("recordList");if(recordList==null){recordList="";}if(message!=null){String oneRecord = "<p>" + username +"说:"+ message + "</p>";recordList +=oneRecord;}getServletContext().setAttribute("recordList", recordList);//getServletContext().setAttribute("username", username);out.println("<!DOCTYPE html>");out.println("<html>");out.println("<head>");out.println("<title>Servlet sendMessage</title>");out.println("</head>");out.println("<body>");out.println("<form action=\"\" name=\"sendMessage\" method=\"post\">");out.println("<center><textarea rows=\"15\" cols=\"100\" name=\"message\">");out.println("</textarea></center>");out.println("<div align=\"right\">");out.println("<tr>");out.println("<input type=\"submit\" name=\"send\" value=\"发送\">");out.println("<input type=\"reset\" name=\"reset\">");out.println("<a href=\"http://localhost:8080/chatRoom/Login.jsp\">返回</a>");out.println("</tr>");out.println("</form>");out.println("</body>");out.println("</html>");}}。