Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

jspÖ®session

     session¾ÍÊÇÒ»¸öÈ«¾Ö±äÁ¿£¬ÊÇä¯ÀÀÆ÷Ïß³ÌÔÚ·þÎñÆ÷¶ËµÄ´úÀí¡£web·þÎñ³ÌÐòÖ»Òª´ò¿ª£¬session¾Í»á´æÔÚ£¬µ±ÄãµÚÒ»´Î·ÃÎÊʱ£¬session»á×Ô¶¯ÎªÄã·ÖÅäÒ»¸ösession ID£¬ËùÒÔsessionΪн¨Á¢µÄ£¬ËùÒÔsession.isNew()Ϊtrue¡£µ±ÄãË¢ÐÂÒ³ÃæÊ±£¬Õâ¸ösession IDÒ»Ö±´æÔÚ(session.getId()²»±ä)£¬²»»áÏûʧ£¬ËùÒÔsession.isNew()Ϊfalse¡£³ý·ÇÄã¹Ø±ÕÄãÒª·ÃÎʵÄwebÕ¾µã£¬»òÔò¹Ø±Õsession(session.invalidate())£¬Õâ¸ösession ID²Å»áÏûʧ(session.getId()±äÁË),isNew()Ϊtrue¡£
Á½¸ö·½·¨ session.isNew() ÅжÏÊÇ·ñÊÇÒ»¸öÐÂsession
               session.getId() µÃµ½Õâ¸ösession id
µ±¹Ø±ÕËùÓеÄä¯ÀÀÆ÷£¬ÔÙÖØÐµÇ¼µÄʱºòsession.isNew()²Å»áÊÇtrue
µ±Ã¿´Î¶¼Ð´ò¿ªÒ»¸öä¯ÀÀÆ÷Óò»Í¬µÄÓû§µÇ¼£¬session.isNew() ÊÇΪfalse¡£session.getId()ÊDz»±äµÄ,¡£
¼´£ºsession idÏ൱ÊÇ´ò¿ªÒ»¸öä¯ÀÀÆ÷½ø³Ì(²»ÊÇÏß³Ì)ʱweb·þÎñÆ÷Ϊ±¾ä¯ÀÀÆ÷½ø³Ì·ÖÅäµÄid
³£Ó÷½·¨£º
  long create_time = session.getCreationTime();    //session´´½¨Ê±¼ä
  long access_time = session.getLastAccessedTime();//session×îºó·ÃÎÊʱ¼ä
 //´òÓ¡sessionÀïÃæµÄattributeÖµ
  Enumeration elements = session.getAttributeNames();
  while (elements.hasMoreElements()) {
       String id = (String)elements.nextElement();
   }
response.setHeader("Refresh","5;url=/session_filter_listener/index.jsp");//ÿ5ÃëÖÓˢУ¬È»ºó¶¨Î»µ½index.jsp


Ïà¹ØÎĵµ£º

jsp¼¸ÖÖ·½·¨

1.±ØÐë¼Ì³Ð×ÔHttpServlet
  2.±ØÐëʵÏÖdoGet()»òÕßdoPost()
  3.±ØÐëÔÚweb.xmlÖÐÅäÖÃServlet
  <servlet>
  <servlet-name> </servlet-name>
  <servlet-class> </servlet-class>
  </servlet>
  <servlet-mapping>
  ......

JSPʵÀýÈý¡¢sql·ÖÒ³(1)

index.jsp
<%@ page language="java" import="java.sql.*" import="java.lang.*" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
& ......

JSPÒ³Ãæµ÷ÓÃjsÖÐÎÄÂÒÂë

jspÖеÚÒ»¾ä£º
<%@ page language="java" import="java.sql.*,java.util.*,"  contentType="text/HTML;charset=gb2312" pageEncoding="gb2312"%>
htmlÖмÓÉÏ
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
ͨ³£ÕâÑù¾ÍûÓÐÎÊÌâÁË¡£    .
ÔÙÕߣº µ¼ÈëjsʱºòÉ ......

jsp:forward±êÇ©ºÍresponse.sendRedirect()·½·¨µÄÇø±ð

ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËÒ»Ð©Çø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔ­À´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼­,·¢ËÍÒ»¸ö×´ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ