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???

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.