当前位置:首页 > 中南民族大学JavaEE实验报告(聊天室,购物车)
/*
* To change this template, choose Tools | Templates * and open the template in the editor. */
package com.servlet;
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.*; import javax.servlet.http.*; /** *
* @author huxiao */
public class loginsucess extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //TODO Method stub generated by Lomboz response.setContentType(\
String name=request.getParameter(\ HttpSession session=request.getSession();
String history =(String)getServletContext().getAttribute(\ if(history==null) history=\
String temp =(String)getServletContext().getAttribute(\ if(temp==null) temp=\
PrintWriter out = response.getWriter(); try{
out.println(\http-equiv=\\\content=\\%url=response.encodeURL(\\\
out.println(\
out.println(\ align=\\\欢迎来到聊天室 \
out.println(\bgcolor=#00aabb behavior=alternate><<<<<<<<希望大家聊的开心>>>>>>>\
out.println (\在线人数:\历史访问次数:\ out.println(\
String tempHistory=(String)getServletContext().getAttribute(\ if(tempHistory==null) tempHistory=\
out.println(\cols=\\\ rows=\\\name=\\\style=\\\ out.println(); out.println(\ out.println(\
out.println(\ out.println(\ cols=\\\ rows=\\\style=\\\name=\\\
out.println(\
out.println(\ name=\\\发送\\\ out.println(\ name=\\\取消\\\ out.println(\
out.println(\ }finally{ out.close(); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
String user=request.getParameter(\
session.setAttribute(\ processRequest(request,response); } }
5、 登录失败 faillogin.java /*
* To change this template, choose Tools | Templates * and open the template in the editor. */
package com.servlet;
import java.io.*;
import javax.servlet.*; import javax.servlet.http.*; /** *
* @author huxiao */
public class loginfail extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //TODO Method stub generated by Lomboz doPost(request,response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //TODO Method stub generated by Lomboz response.setContentType(\ PrintWriter out = response.getWriter(); out.println(\
out.println(\ out.println(\ out.println(\登录失败\ out.println(\ out.println(\ out.println(\ out.println(\登录失败!!!请重新登录。。。\
RequestDispatcher dispatcher =request.getRequestDispatcher(\ dispatcher.include(request, response); out.println(\ out.println(\ out.close(); } }
6、 任务监听 sessionListener.java
/*
* To change this template, choose Tools | Templates * and open the template in the editor. */
package com.servlet;
import javax.servlet.annotation.WebListener; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; /**
* Web application lifecycle listener. *
* @author Josh */
@WebListener()
public class SessionListener implements HttpSessionListener {
@Override
public void sessionCreated(HttpSessionEvent se) {
String current=(String)se.getSession().getServletContext().getAttribute(\ if(current==null) current=\
int c=Integer.parseInt(current); c++;
current=String.valueOf(c);
se.getSession().getServletContext().setAttribute(\
String his=(String)se.getSession().getServletContext().getAttribute(\ if(his==null) his=\
int total=Integer.parseInt(his)+1; his=String.valueOf(total);
se.getSession().getServletContext().setAttribute(\ }
@Override
public void sessionDestroyed(HttpSessionEvent se) {
String current=(String)se.getSession().getServletContext().getAttribute(\ if(current==null) current=\
int c=Integer.parseInt(current); c--;
current=String.valueOf(c);
se.getSession().getServletContext().setAttribute(\ } }
7、 计数文件 CountFile.java
/*
* To change this template, choose Tools | Templates * and open the template in the editor. */
package com.servlet; import java.io.*; /** *
* @author huxiao */
共分享92篇相关文档