title: how can i prevent a user from directly accessing a pages if not authenticated?
body: <p>I am using custom tag and i want to know how can i prevent a user from directly accessing my application pages without authenticating.  Below is the view page coding, please let me know how to go about it, I even tried using page session directive but that didnt work.</p>
  
  <pre><code>  &lt;html&gt;
    &lt;head&gt;
    &lt;script&gt;
        function check(submit)
        {
      var x = document.getElementById("r");
      var xlength=x.value.length;
      if(xlength!=5 || x=="")
    {
                 alert("Enter 5 digit Employee Id");
                 document.getElementById("r").focus();
  return false;
   }
   }
   &lt;/script&gt;  
    &lt;/head&gt;
    &lt;body&gt;
    &lt;form method=post&gt;
    &lt;input type=text style="color:grey" name=reqno id=r 
  
    value=requestno maxlength="5" onFocus="if 
  
    (this.value==this.defaultValue) this.value=''" onblur="if 
  
    (this.value=='') this.value = this.defaultValue" &gt;
    &lt;/br&gt;
    &lt;input type = submit name = submit value = Submit 
  
     onclick="return check(this)" &gt;
    &lt;input type = submit name = back value = Back&gt;
  
  &lt;%
  
    String r=request.getParameter("reqno");
    String btn=request.getParameter("submit");
    String btn1=request.getParameter("back");
    HttpSession session1=request.getSession();
    session1.setAttribute("requestno",r);
   if (btn!=null)
     response.sendRedirect("findrequest1.jsp");
   else if (btn1!=null)
     response.sendRedirect("selectaction.jsp");
  
  
  %&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the Login Page</p>
  
  <pre><code>&lt;jsp:useBean id="theBean" class="pack.java.MyModel"/&gt;
  &lt;jsp:setProperty name="theBean" property="name" param="userName"/&gt;
  &lt;jsp:setProperty name="theBean" property="pass" param="userPass"/&gt;
  &lt;%@ taglib uri="taglib1.tld" prefix="easy" %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
   history.forward();
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;header&gt;
  &lt;h4 align="right"&gt;&lt;a href="projectregister.jsp"&gt;Register Now&lt;/a&gt;&lt;/br&gt;
  &lt;/h4&gt;
  &lt;/header&gt;
   &lt;form = "loginform" method="post"&gt;
  &lt;h1&gt;Login please&lt;/h1&gt;
  Enter username : &lt;input type = text  name = userName  &gt;
  &lt;/br&gt;
  Enter password : &lt;input type = password  name = userPass  &gt;
  &lt;/br&gt;
  &lt;input type = submit name = submit value = submit&gt;
  &lt;/br&gt;
  &lt;%
  String btn = request.getParameter("submit");
  String uu= request.getParameter("userName");
  String pp= request.getParameter("userPass");
  HttpSession sessions=request.getSession();
  String st=(String)request.getAttribute("user");
  
    if(request.getParameter("userName")!="" &amp;&amp; request.getParameter("userPass")!="")
  {
    if (btn!=null )
  {
  
  %&gt;
  &lt;easy:myTag/&gt;
  &lt;% 
  }
  }
  %&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is a filter</p>
  
  <pre><code>       package pack.java;
         import java.io.*;
         import javax.servlet.*;
  
         public class loginfilter implements Filter
       {
          String aa;
      public void destroy()
          {
          }
  
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
   {
      aa=request.getRequestURI();
      chain.doFilter(request, response);
   }
  
    public void init(FilterConfig fconfig) throws ServletException
   {
    }
  
  }
  </code></pre>
  
  <p>This the Login (controller) page</p>
  
  <pre><code>   package pack.java;
     import pack.java.MyModel;
     import java.io.*;
     import java.lang.*;
     import javax.servlet.*;
     import javax.servlet.http.*;
     import javax.servlet.jsp.*;
     import javax.servlet.jsp.tagext.*;
     import java.sql.*;
      public class MyController extends TagSupport
   {
  
  HttpServletRequest request;
  HttpServletResponse response;
  String msg="";
  String empid="";
      public int doStartTag()throws JspException
  {
  
   request=(HttpServletRequest)pageContext.getRequest();              
   response=(HttpServletResponse)pageContext.getResponse();
      return EVAL_PAGE;
   }  
  
      public void check()
   {
  
     HttpSession mysession=request.getSession();
  
      JspWriter out=pageContext.getOut();
      int f=0;
      try
    {
     Class.forName("oracle.jdbc.driver.OracleDriver");
    }
     catch(ClassNotFoundException ex)
    {
      msg=ex.getMessage();
    }
      try 
   {   
       Connection con;
       CallableStatement stmt;
       ResultSet rs;
       String aa=(String)MyModel.name.trim();
       String bb=(String)MyModel.pass.trim();
  
   if(!aa.matches(".*[%#^&lt;&gt;&amp;;'\0-].*") &amp;&amp; !bb.matches(".*[%#^&lt;&gt;&amp;;'\0-].*"))
  {
  
   con=    DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","gaurav","oracle");
      stmt=con.prepareCall("select usercheck1(?,?) from dual");
      stmt.setString(1,aa);
      stmt.setString(2,bb);       
      rs=stmt.executeQuery();
  
    while (rs.next())
   {
     empid=rs.getString (1);     
    mysession.setAttribute("user",empid);
  
    if(empid!=null)
   {
    response.sendRedirect("/Myjsp/selectaction.jsp");
   }
     else 
     out.println("Invalid Details");
   }
   }
    else
    out.println("Invalid Details");
  }
   catch(SQLException ex)
   {
     msg=ex.getMessage();
   }         
    catch(Exception ex)
   {
    msg=ex.getMessage();
  } 
  
  } 
     public int doEndTag() throws JspException
  {
  
      check();
     return EVAL_PAGE;
   }
  
  }
  </code></pre>
  
  <p>In web.xml file below is the code i entered</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;loginfilter&lt;/filter-name&gt;
      &lt;filter-class&gt;pack.java&lt;/filter-class&gt;
   &lt;/filter&gt;
  
  
   &lt;filter-mapping&gt;
      &lt;filter-name&gt;loginfilter&lt;/filter-name&gt;  
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
   &lt;/filter-mapping&gt; 
  </code></pre>