Results 1 to 18 of 18
  1. #1
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Login authenticate at each page in jsp

    i am creating an application that will have multiple pages in it, i want a user to be redirect to login page in case he isnt authenticated already and tries to access some intermediate page...

    i am developing this on jsp

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,260
    Rep Power
    6

    Default Re: Login authenticate at each page in jsp

    So what have you researched so far?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    actually am working on my college project on online movie ticket booking system....I have created the whole project using jsp.
    but the problem in my project is when i paste the URL of shopping cart without loggin
    it's opening that page...
    So, i need to authenticate that page..

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,260
    Rep Power
    6

    Default Re: Login authenticate at each page in jsp

    Yes, so you know what to google don't you? "java jsp user authentication" is a good start. You're a student, research should be nothing new to you.

    Believe me, I have your best interest at heart here. Spoon feeding answers has never helped anyone, so I'm not going to do that. Research some possibilities and if you get stuck choosing one, present your findings and we can discuss them.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    yeah! i did but still i'm not able to get it done...... this is my last alternative left.
    here's my code
    Java Code:
    <%-- 
        Document   : purchase
        Created on : 17 Sep, 2013, 5:25:02 PM
        Author     : Sravan
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@page language="java"%>
    <%@page language="java" import="java.sql.*"%>
    <jsp:include page="layout.jsp"/>
    
    <html>
     <head>
      <title></title>
      <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
      <%
        if(session.getAttribute("myusername").equals("null")){
          String redirectURL = "login.jsp";
    response.sendRedirect(redirectURL);
      }
        else{
      %>
     </head>
     <body>
      <form method="post" action="item_purchase.jsp">
          <br>
          <br>
          <br>
          <div style="margin-top:0; margin-left: 130;height:400px; width:400px;">
     <table border="2" align="center" cellpadding="7" cellspacing="7">
     <tr>
     <td width="399"><strong>Select a Category of your Interest</Strong></td>
     <td width ="277">
         <select name="cat">
      <option value="" selected>--select--</option>
      <%
     
      try{
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/access","access","access");
    Statement st=con.createStatement();
    ResultSet rs= st.executeQuery("Select * from cat_tab");
    while(rs.next()){
    %>
    <option value="<% String catg12 = rs.getString(1); out.print(catg12);%>"><% out.print(catg12);%></option>
    
    <%
    }
    out.print("<select>");
    }
    catch(Exception e){
    e.printStackTrace();
    }
        }
    
    %>
    
         </td>
         <td><input type="submit" value="search"/></td>
    </tr>
    
    </table>
          </div>
    </form>
    </body>
    </html>

  6. #6
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    here's the error:

    An exception occurred processing JSP page /purchase.jsp at line 17

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Login authenticate at each page in jsp

    And what does it say the exception is?
    There should be a full exception including a stack trace somewhere in your logs.

    I think I can spot what the problem is, but the proper exception would help.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    her's the screen shot of the exception
    Login authenticate at each page in jsp-apache-tomcat-7.0.34-error-report.png

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Login authenticate at each page in jsp

    Ha, see?
    I would have been wrong.
    If session.getAttribute("myusername") is null then you will get the above exception.
    So that check needs to use "== null" to decide whether to redirect or not.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    Thanks.
    i'm not getting exception..
    but at the same time the condition is not working...
    just now i opened that page directly without logging in but it's not redirecting

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Login authenticate at each page in jsp

    Is it doing anything?
    Do you get the stuff in the "else" statement appearing, or is the screen just blank?

    Is there anything in the logs on the server?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    i'm getting the else block.
    without loggin in this page is displaying

    Login authenticate at each page in jsp-rainbow-movies1.png

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Login authenticate at each page in jsp

    And what does that if/else block now look like?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    i have uploaded the screen shot of the code above

    here's the code
    Java Code:
    <%-- 
        Document   : purchase
        Created on : 17 Sep, 2013, 5:25:02 PM
        Author     : Sravan
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@page language="java"%>
    <%@page language="java" import="java.sql.*"%>
    <jsp:include page="layout.jsp"/>
    
    <html>
     <head>
      <title></title>
      <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
      <%
        if(session.getAttribute("myusername")=="null" && session.getAttribute("myusername")==""){
          String redirectURL = "login.jsp";
    response.sendRedirect(redirectURL);
      }
        else{
              %>
     </head>
     <body>
      <form method="post" action="item_purchase.jsp">
          <br>
          <br>
          <br>
          <div style="margin-top:0; margin-left: 130;height:400px; width:400px;">
     <table border="2" align="center" cellpadding="7" cellspacing="7">
     <tr>
     <td width="399"><strong>Select a Category of your Interest</Strong></td>
     <td width ="277">
         <select name="cat">
      <option value="" selected>--select--</option>
      <%
     
      try{
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/access","access","access");
    Statement st=con.createStatement();
    ResultSet rs= st.executeQuery("Select * from cat_tab");
    while(rs.next()){
    %>
    <option value="<% String catg12 = rs.getString(1); out.print(catg12);%>"><% out.print(catg12);%></option>
    
    <%
    }
    out.print("<select>");
    }
    catch(Exception e){
    e.printStackTrace();
    }
        }
    
    %>
    
         </td>
         <td><input type="submit" value="search"/></td>
    </tr>
    
    </table>
          </div>
    </form>
    </body>
    </html>

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Login authenticate at each page in jsp

    Java Code:
    if(session.getAttribute("myusername")=="null" && session.getAttribute("myusername")==""){
    That's never going to be true.
    It will never be null and blank.
    Remove the second part.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    i removed that part!
    but still it's not redirecting to login page..if i opened that page withput loggin in

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Login authenticate at each page in jsp

    Sorry, just noticed:
    Java Code:
    session.getAttribute("myusername")=="null"
    There's no quotes round null there.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    shyamgsk is offline Member
    Join Date
    Sep 2013
    Location
    Hyerabad,India
    Posts
    20
    Rep Power
    0

    Default Re: Login authenticate at each page in jsp

    wow....@Tolls

    Thanks a lot!
    atlast it worked....

    Thank you!

Similar Threads

  1. ejb login page
    By mtrsykl in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 05-07-2013, 11:52 AM
  2. JSP login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-06-2008, 05:23 AM
  3. login page
    By keerthi_y19 in forum New To Java
    Replies: 9
    Last Post: 08-06-2008, 12:58 PM
  4. Login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-03-2008, 03:05 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •