Servlet 基礎
全部的servlet都是從HttpServlet繼承而來的.
Servlet配置:在web.xml中
- <servlet>
- <servlet-name>
- </servlet-name>
- <servlet-class>
- </servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>
- </servlet-name>
- <url-pattern>
- </url-pattern>
- </servlet-mapping>
過慮器
注意過慮器是雙向過慮的.
- public class Filter1 implements javax.servlet.Filter {
-
- public void init(FilterConfig config)
- throws ServletException() {
-
- }
-
- public void destory(){}
-
- public void doFilter(ServletRequest request,
- ServletResponse response,
- FilterChain chain)
- throws IOException, ServletException {
- System.out.println("request 來的時候");
- chain.doFilter(request, response);
- System.out.println("response 回來的時候");
- }
-
- }
Filter配置信息:
- <filter>
- <filter-name></filter-name>
- <filter-class></filter-class>
- </filter>
- <filter-mapping>
- <filter-name></filter-name>
- <url-pattern>*</url-pattern>
- </filter-mapping>
Filter的執行順序嚴格按照web.xml裏的配置順序.
---------------
裝飾模式
裝飾者
被裝飾者
分頁
- select top pageNo*pageSize * from bean
- where beanId not in
- (select top (pageNo-1).pageSize * from bean)
圖形驗證碼
監聽器
支持在ServletContext, HttpSession和ServletRequest對象變化時提供的通知.
- <listener>
- <listener-class />
- </listener>
註冊時不分前後順序
- public class OnlineListener implements ServletContextListener {
- public void contextDestroyed(ServletContextEvent event) {
- }
- public void contextInitialized(ServletContextEvent event) {
- ServletContext application = event.getServletContext();
- // to do
- }
- }
在web.xml中配置以下信息:
- <listener>
- <listener-class>OnlineListener</listener-class>
- </listener>
對不一樣的session應用不一樣的session HttpSessionBindingListener