⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessionrecorderservlet.java

📁 icsamples目录中有icsamples网络程序。 这个程序包括J2EE网络层的范例程序
💻 JAVA
字号:
/* * Class.java * Example shows how to cound the request to a certain servlet * Created on October 9, 2002, 1:27 PM */package jwadbook.servlets;/** * * @author  cai */import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.util.*;public class SessionRecorderServlet extends HttpServlet {                 public void init() throws ServletException {        	}                public void doPost ( HttpServletRequest req, HttpServletResponse resp ) 			throws ServletException,IOException	{                GregorianCalendar current = new GregorianCalendar();                int hour = current.get(Calendar.HOUR_OF_DAY);                int min = current.get(Calendar.MINUTE);                String time = String.valueOf(hour) +":"+ String.valueOf(min);                                HttpSession cusession = req.getSession(true);                cusession.setAttribute("Last_Access_Time", time);                                cusession.setAttribute("Protocol", req.getProtocol());                cusession.setMaxInactiveInterval(3600*24);                                if(cusession.getAttribute("Access_Recorder")!=null)                {                    ((Vector)cusession.getAttribute("Access_Recorder")).addElement(req.getRemoteHost());                }                else                {                    cusession.setAttribute("Access_Recorder", new Vector());                }          PrintWriter out = resp.getWriter();		resp.setContentType("text/html");		out.println(" <HTML> ");		out.println(" <HEAD>");		out.println(" <TITLE>SessionRecorderServlet</TITLE> ");		out.println(" </HEAD> ");		out.println(" <BODY BGCOLOR=white> ");		out.println(" <CENTER> ");		out.println(" <FONT COLOR='#009999' SIZE='4' face='Arial'> ");		out.println(" <STRONG>Use Session to Record Access to this Servlet</STRONG> ");		out.println(" </FONT> ");		out.println(" </CENTER> ");		out.println(" <HR>");		out.println("<CENTER>Please See Results in <A href = '/icsamples/sessionreader'> SessionReader </A> Servlet</CENTER><br>  ");		out.println(" <HR> ");		out.println(" </BODY> ");		out.println(" </HTML> " );		out.flush();	}        public void doGet ( HttpServletRequest req, HttpServletResponse resp ) 			throws ServletException,IOException	{		doPost(req,resp);	}        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -