|
using session to protect a page in jsp
|
|
12-13-2011, 12:17 AM
Post: #1
|
|||
|
|||
|
In web projects it is important to protect certain pages from users to access directly. There are many complicated ways to do that but here iam going to give you an easy way to do that using sessions. First in login page(login.jsp) set the session variable to username that is get from the login username and password box. When user login check if that user is a autheticated user,if it is set the session variable. <%session.setAttribute("name",username);%*> otherwise redirect user to login page. Then give check the condition below in the page you want to protect At start of page "authenticate.jsp" <%String check=(String)(session.getAttribute("name")); if(check!=null) { %> <html> Write all your html or jsp code for the page here </html> <} else { %> <jsp:forward Page="login.jsp"%> <}> Now if the user without login try to access this page "authenticate.jsp" will be forwarded to login page once he logged in he will access this page. Any doubts ask us. Happy coding
|
|||
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
User(s) browsing this thread: 1 Guest(s)






![[-]](images/royal_red/collapse.gif)






