Servlet使用

1.1重定向(如果对方不支持cookie,回写sessionID进行session跟踪)
 response.sendRedirect(response.encodeRedirectURL(request.getContextPath()+"/next"));
******************************************************************
1.2转发
 RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
 dispatcher.forward(request,response);
******************************************************************
1.3字符
  request.setCharacterEncoding("utf-8");
  response.setContentType("text/html;charset=utf-8");
******************************************************************
String servletPath = request.getServletPath();
  servletPath = servletPath.substring(servletPath.lastIndexOf("/") + 1);
  String operation = servletPath.substring(0, servletPath.indexOf(".do"));
1.设置连接超时时间(分钟)
 <session-config>
  <session-timeout>50</session-timeout>
 </session-config>
******************************************************************
4.相对路径匹配
 1>绝对匹配 /xx/yy
 2>后缀匹配 *.xx
 3>后面匹配 /xx/*
******************************************************************
5.监听器
5.1ServletRequestListener
   getServletContext()
   getServletRequest()
 requestDestroyed(ServletRequestEvent)
 requestInitialized(ServletRequestEvent)
5.2HttpSessionListener
   getSession()
 sessionCreated(HttpSessionEvent)
 sessionDestroyed(HttpSessionEvent)
5.3ServletContextListener
   getServletContext()
 contextInitialized(ServletContextEvent)
 contextDestroyed(ServletContextEvent)
 
5.4ServletRequestAttributeListener
   getName()
   getValue()
 attributeAdded(ServletRequestAttributeEvent)
 attributeRemoved(ServletRequestAttributeEvent)
 attributeReplaced(ServletRequestAttributeEvent)
5.5HttpSessionAttributeListener
   getName()
   getValue()
   getSession()
 attributeAdded(HttpSessionBindingEvent)
 attributeRemoved(HttpSessionBindingEvent)
 attributeReplaced(HttpSessionBindingEvent)
5.6ServletContextAttributeListener
   getName()
   getValue()
 attributeAdded(ServletContextAttributeEvent)
 attributeRemoved(ServletContextAttributeEvent)
 attributeReplaced(ServletContextAttributeEvent)

posted on 2008-04-19 20:31 金家寶 阅读(396) 评论(0)  编辑  收藏 所属分类: J2EE 基础


只有注册用户登录后才能发表评论。


网站导航: