steven
steven

Reputation: 13

don't allow non member show jsp page

i design a jsp page but i want only some one that login as member of my site(have session with some futures) see that page and if some one that is not member try to see page refer to a custom eror page.can you advise me something helpfull?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> User Account</title>
</head>
<body>
<%@include file="Header.jsp" %>
${welcome } ${name} ${family }
</body>
</html>

any help fall me in greatfull...

Upvotes: 0

Views: 145

Answers (1)

Bozho
Bozho

Reputation: 597076

Use a servlet filter.

  1. Implement javax.servlet.Filter. Call chain.doFilter(..) only if you find a user in the session; otherwise call response.sendRedirect("notLoggedIn.jsp");
  2. Map it in web.xml (<filter> and <filter-mapping>) (or if you are using servlet 3.0 - use @WebFilter on the filter class). Map the filter to the path(s) you want to protect.

Upvotes: 1

Related Questions