0

hi all,
I'm new to jsp.can any one help me to set URL authentication ?i.e., the user should use the link only by login not by typing in the URL. can anyone plz???

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by javaAddict
0

hi all,
I'm new to jsp.can any one help me to set URL authentication ?i.e., the user should use the link only by login not by typing in the URL. can anyone plz???

When the user logs in, put the username in the session. Example:

String username = request.getParameter("username");

// do some validations with the username
// if the log in was successful:

session.setAttribute("USERNAME", username);

When the user logs out, remove the username from the session:

session.setAttribute("USERNAME", null);

In every page (jsp file) that you have you can do this:

<%
String username = (String)session.getAttribute("USERNAME");
if (username==null) {
%>
  <script>
      alert("You must login first");
  </script>
  <jsp:forward page="login.jsp" />
<%
}
%>

Be careful. You must put the username in the session only when the log in was successful. If the user has entered correct username and password

Edited by javaAddict: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.