Enter your email address:

Delivered by FeedBurner


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using session to protect a page in jsp
12-13-2011, 12:17 AM
Post: #1
Big Grin using session to protect a page in jsp
Everyone already know how to creating sessions if you don't know read this tutorial In order to view links, you must have to reply to this thread.
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
Find all posts by this user
Add Thank You Quote this message in a reply
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
Post Reply 


[-]
Share/Bookmark (Show All)
Facebook Linkedin Technorati Twitter Digg MySpace Delicious

Possibly Related Threads...
Thread: Author Replies Views: Last Post
Big Grin In Tomcat jsp page is not refreshing rajasri 0 199 12-19-2011 06:11 PM
Last Post: rajasri
Thumbs Up Display combo box value/Database value on same JSP page rajasri 0 326 12-19-2011 04:57 PM
Last Post: rajasri
Its My Birthday! Display database value in jsp page rajasri 0 609 12-14-2011 11:43 AM
Last Post: rajasri
Video simple update query in jsp page rajasri 0 1,067 12-14-2011 11:36 AM
Last Post: rajasri
Shocked update using parameters in jsp page rajasri 0 434 12-14-2011 11:34 AM
Last Post: rajasri
Video Display current time and date in your Jsp page rajasri 0 957 12-12-2011 11:56 PM
Last Post: rajasri
Star Getting number of rows in jsp page rajasri 0 587 12-12-2011 11:53 PM
Last Post: rajasri
Star Read data from xml and show in jsp page project download rajasri 0 951 12-12-2011 11:30 PM
Last Post: rajasri
Bug Print current time using java in jsp page rajasri 0 620 12-12-2011 11:20 PM
Last Post: rajasri
  Redirect page using jsp to another page admin 0 1,128 11-28-2011 06:49 PM
Last Post: admin

Forum Jump:


User(s) browsing this thread: 1 Guest(s)