Difference between revisions of "Password protecting pages"
From MyWiki
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A working example from GetNewUser, needs improving :<br> | A working example from GetNewUser, needs improving :<br> | ||
− | 1. Look up the session information | + | 1. Look up the session information, if the session table is empty then redirect to the login page. |
<source lang="java"> | <source lang="java"> | ||
String getIt = "SELECT user from sessions where session = '"+session.getId()+"'"; | String getIt = "SELECT user from sessions where session = '"+session.getId()+"'"; | ||
stmt = conn.createStatement(); | stmt = conn.createStatement(); | ||
+ | rs = stmt.executeQuery(getIt); | ||
+ | |||
+ | if ( rs.next() ) { | ||
+ | USERNAME = rs.getString("user") ; | ||
+ | out.println("Your username is : "+USERNAME); | ||
+ | int length = USERNAME.length(); | ||
+ | } | ||
+ | else response.sendRedirect("login.jsp"); | ||
+ | </source> | ||
+ | |||
+ | In jsp this is how I do it : | ||
+ | <source lang="java"> | ||
+ | String ff = session.getId(); | ||
+ | String myUrl = "emailformServlet.jsp"; | ||
+ | CheckSessionId qq = new CheckSessionId(); | ||
+ | String ab=qq.checkIt(ff,myUrl); | ||
+ | if ( ab.length() < 3) response.sendRedirect("https://barkus.bold.ac.uk/userregister/login.jsp"); | ||
+ | String cc = " is loggged in"; | ||
+ | |||
</source> | </source> |
Latest revision as of 10:33, 4 November 2014
A working example from GetNewUser, needs improving :
1. Look up the session information, if the session table is empty then redirect to the login page.
String getIt = "SELECT user from sessions where session = '"+session.getId()+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(getIt); if ( rs.next() ) { USERNAME = rs.getString("user") ; out.println("Your username is : "+USERNAME); int length = USERNAME.length(); } else response.sendRedirect("login.jsp");
In jsp this is how I do it :
String ff = session.getId(); String myUrl = "emailformServlet.jsp"; CheckSessionId qq = new CheckSessionId(); String ab=qq.checkIt(ff,myUrl); if ( ab.length() < 3) response.sendRedirect("https://barkus.bold.ac.uk/userregister/login.jsp"); String cc = " is loggged in";