Lara

JSP

Monday(16-01-2017)

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

 

/**

 * Servlet implementation class Servlet7

 */

public class Servlet7 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet7() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        HttpSession s1 = request.getSession();

                        s1.setAttribute("attr1", "Hello");

                        PrintWriter out = response.getWriter();

                        out.println("check in the console");

            }

 

}

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

 

/**

 * Servlet implementation class Servlet8

 */

public class Servlet8 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet8() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        HttpSession s1 = request.getSession();

                        s1.removeAttribute("attr1");

                        PrintWriter out = response.getWriter();

                        out.println("check in the console");

            }

 

}

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

 

/**

 * Servlet implementation class Servlet6

 */

public class Servlet6 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet6() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        HttpSession s1 = request.getSession();

                        s1.setAttribute("attr1", "Hello");

                        PrintWriter out = response.getWriter();

                        out.println("check in the console");

            }

 

}

package com.lara;

 

import javax.servlet.http.HttpSessionBindingEvent;

import javax.servlet.http.HttpSessionBindingListener;

 

/**

 * Application Lifecycle Listener implementation class Person

 *

 */

public class Person implements HttpSessionBindingListener {

 

    /**

     * Default constructor.

     */

    public Person() {

        // TODO Auto-generated constructor stub

    }

 

            /**

     * @see HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)

     */

    public void valueBound(HttpSessionBindingEvent arg0)  {

         System.out.println("value bound with session");

    }

 

            /**

     * @see HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)

     */

    public void valueUnbound(HttpSessionBindingEvent arg0)  {

         System.out.println("value unboubd with session");

    }

           

}

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

 

/**

 * Servlet implementation class Servlet9

 */

public class Servlet9 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet9() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        Person p1 = new Person();

                        HttpSession s1 = request.getSession();

                        s1.setAttribute("personObj", p1);

                        PrintWriter out = response.getWriter();

                        out.println("check in the console");

            }

 

}

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

 

/**

 * Servlet implementation class Servlet10

 */

public class Servlet10 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet10() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        HttpSession s1 = request.getSession();

                        s1.removeAttribute("personObj");

                        PrintWriter out = response.getWriter();

                        out.println("check in the console");

            }

 

}

 

 

 

package com.lara;

 

import javax.servlet.ServletRequestEvent;

import javax.servlet.ServletRequestListener;

 

/**

 * Application Lifecycle Listener implementation class RequestLifeCycleListener

 *

 */

public class RequestLifeCycleListener implements ServletRequestListener {

 

    /**

     * Default constructor.

     */

    public RequestLifeCycleListener() {

        // TODO Auto-generated constructor stub

    }

 

            /**

     * @see ServletRequestListener#requestDestroyed(ServletRequestEvent)

     */

    public void requestDestroyed(ServletRequestEvent arg0)  {

         System.out.println("req object destroyed");

    }

 

            /**

     * @see ServletRequestListener#requestInitialized(ServletRequestEvent)

     */

    public void requestInitialized(ServletRequestEvent arg0)  {

         System.out.println("req object created");

    }

           

}

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

/**

 * Servlet implementation class Servlet11

 */

public class Servlet11 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet11() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                       

                        System.out.println("request processing");

                        PrintWriter out = response.getWriter();

                        out.println("check in the console");

            }

 

}

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app2</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  <servlet>

    <description></description>

    <display-name>Servlet1</display-name>

    <servlet-name>Servlet1</servlet-name>

    <servlet-class>com.lara.Servlet1</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet1</servlet-name>

    <url-pattern>/Servlet1</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet2</display-name>

    <servlet-name>Servlet2</servlet-name>

    <servlet-class>com.lara.Servlet2</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet2</servlet-name>

    <url-pattern>/Servlet2</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet3</display-name>

    <servlet-name>Servlet3</servlet-name>

    <servlet-class>com.lara.Servlet3</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet3</servlet-name>

    <url-pattern>/Servlet3</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet4</display-name>

    <servlet-name>Servlet4</servlet-name>

    <servlet-class>com.lara.Servlet4</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet4</servlet-name>

    <url-pattern>/Servlet4</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet5</display-name>

    <servlet-name>Servlet5</servlet-name>

    <servlet-class>com.lara.Servlet5</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet5</servlet-name>

    <url-pattern>/Servlet5</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet6</display-name>

    <servlet-name>Servlet6</servlet-name>

    <servlet-class>com.lara.Servlet6</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet6</servlet-name>

    <url-pattern>/Servlet6</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet7</display-name>

    <servlet-name>Servlet7</servlet-name>

    <servlet-class>com.lara.Servlet7</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet7</servlet-name>

    <url-pattern>/Servlet7</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet8</display-name>

    <servlet-name>Servlet8</servlet-name>

    <servlet-class>com.lara.Servlet8</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet8</servlet-name>

    <url-pattern>/Servlet8</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet9</display-name>

    <servlet-name>Servlet9</servlet-name>

    <servlet-class>com.lara.Servlet9</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet9</servlet-name>

    <url-pattern>/Servlet9</url-pattern>

  </servlet-mapping>

  <servlet>

    <description></description>

    <display-name>Servlet10</display-name>

    <servlet-name>Servlet10</servlet-name>

    <servlet-class>com.lara.Servlet10</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet10</servlet-name>

    <url-pattern>/Servlet10</url-pattern>

  </servlet-mapping>

  <listener>

    <listener-class>com.lara.RequestLifeCycleListener</listener-class>

  </listener>

  <servlet>

    <description></description>

    <display-name>Servlet11</display-name>

    <servlet-name>Servlet11</servlet-name>

    <servlet-class>com.lara.Servlet11</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet11</servlet-name>

    <url-pattern>/Servlet11</url-pattern>

  </servlet-mapping>

</web-app>

 App3

Tuesday(17-01-2017)

package com.lara;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

/**

 * Servlet implementation class Servlet1

 */

public class Servlet1 extends HttpServlet {

            private static final long serialVersionUID = 1L;

      

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Servlet1() {

        super();

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

             */

            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        System.out.println("From Servlet1");

                        PrintWriter out = response.getWriter();

                        out.println("Check in the console");

            }

 

}

package com.lara;

 

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

 

/**

 * Servlet Filter implementation class Filter1

 */

public class Filter1 implements Filter {

 

    /**

     * Default constructor.

     */

    public Filter1() {

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see Filter#destroy()

             */

            public void destroy() {

                        System.out.println("Filter1-destroy");

            }

 

            /**

             * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)

             */

            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

                        System.out.println("Filter1-doFilter-begin");

                        chain.doFilter(request, response);

                        System.out.println("Filter1-doFilter-end");

            }

 

            /**

             * @see Filter#init(FilterConfig)

             */

            public void init(FilterConfig fConfig) throws ServletException {

                        System.out.println("Filter1-init");

            }

 

}

package com.lara;

 

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

 

/**

 * Servlet Filter implementation class Filter2

 */

public class Filter2 implements Filter {

 

    /**

     * Default constructor.

     */

    public Filter2() {

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see Filter#destroy()

             */

            public void destroy() {

                        System.out.println("Filter2-destroy");

            }

 

            /**

             * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)

             */

            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

                        System.out.println("Filter2-doFilter-begin");

                        chain.doFilter(request, response);

                        System.out.println("Filter2-doFilter-end");

            }

 

            /**

             * @see Filter#init(FilterConfig)

             */

            public void init(FilterConfig fConfig) throws ServletException {

                        System.out.println("Filter2-init");

            }

 

}

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app3</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  <servlet>

    <description></description>

    <display-name>Servlet1</display-name>

    <servlet-name>Servlet1</servlet-name>

    <servlet-class>com.lara.Servlet1</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet1</servlet-name>

    <url-pattern>/Servlet1</url-pattern>

  </servlet-mapping>

  <filter>

    <display-name>Filter1</display-name>

    <filter-name>Filter1</filter-name>

    <filter-class>com.lara.Filter1</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>Filter1</filter-name>

    <servlet-name>Servlet1</servlet-name>

  </filter-mapping>

  <filter>

    <display-name>Filter2</display-name>

    <filter-name>Filter2</filter-name>

    <filter-class>com.lara.Filter2</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>Filter2</filter-name>

    <servlet-name>Servlet1</servlet-name>

  </filter-mapping>

</web-app>

 Wednesday(18-01-2017)

package com.lara;

 

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

 

/**

 * Servlet Filter implementation class Filter3

 */

public class Filter3 implements Filter {

 

            private FilterConfig config;

           

 

            /**

             * @see Filter#destroy()

             */

            public void destroy() {

                        // TODO Auto-generated method stub

            }

 

            /**

             * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)

             */

            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

                        String s1 = config.getInitParameter("param1");

                        String s2 = config.getInitParameter("param2");

                        System.out.println("from Filter3");

                        System.out.println(s1);

                        System.out.println(s2);

                        chain.doFilter(request, response);

            }

 

            /**

             * @see Filter#init(FilterConfig)

             */

            public void init(FilterConfig fConfig) throws ServletException {

                        this.config = fConfig;

            }

 

}

package com.lara;

 

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletContext;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

 

/**

 * Servlet Filter implementation class Filter4

 */

public class Filter4 implements Filter {

 

            private FilterConfig config;

           

    /**

     * Default constructor.

     */

    public Filter4() {

        // TODO Auto-generated constructor stub

    }

 

            /**

             * @see Filter#destroy()

             */

            public void destroy() {

                        // TODO Auto-generated method stub

            }

 

            /**

             * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)

             */

            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

                        ServletContext context = config.getServletContext();

                        String s1 = context.getInitParameter("driver");

                        System.out.println("driver class:" + s1);

                        chain.doFilter(request, response);

                       

            }

 

            /**

             * @see Filter#init(FilterConfig)

             */

            public void init(FilterConfig fConfig) throws ServletException {

                        config = fConfig;

            }

 

}

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app3</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  <servlet>

    <description></description>

    <display-name>Servlet1</display-name>

    <servlet-name>Servlet1</servlet-name>

    <servlet-class>com.lara.Servlet1</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Servlet1</servlet-name>

    <url-pattern>/Servlet1</url-pattern>

  </servlet-mapping>

  <filter>

    <display-name>Filter1</display-name>

    <filter-name>Filter1</filter-name>

    <filter-class>com.lara.Filter1</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>Filter1</filter-name>

    <servlet-name>Servlet1</servlet-name>

  </filter-mapping>

  <filter>

    <display-name>Filter2</display-name>

    <filter-name>Filter2</filter-name>

    <filter-class>com.lara.Filter2</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>Filter2</filter-name>

    <servlet-name>Servlet1</servlet-name>

  </filter-mapping>

  <filter>

    <display-name>Filter3</display-name>

    <filter-name>Filter3</filter-name>

    <filter-class>com.lara.Filter3</filter-class>

    <init-param>

      <description></description>

      <param-name>param1</param-name>

      <param-value>100</param-value>

    </init-param>

    <init-param>

      <description>abc</description>

      <param-name>param2</param-name>

      <param-value>3000</param-value>

    </init-param>

  </filter>

  <filter-mapping>

    <filter-name>Filter3</filter-name>

    <servlet-name>Servlet1</servlet-name>

  </filter-mapping>

  <filter>

    <display-name>Filter4</display-name>

    <filter-name>Filter4</filter-name>

    <filter-class>com.lara.Filter4</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>Filter4</filter-name>

    <servlet-name>Servlet1</servlet-name>

  </filter-mapping>

 

  <context-param>

            <param-name>driver</param-name>

            <param-value>oracle.jdbc.driver.OracleDriver</param-value>

  </context-param>

 

</web-app>