s saravanan wrote:
> Hi All,
>
> I have some help regarding restriction of pages in browsers.
>
> I have created 3 html pages. First page is a homepage where the user login
> is there. The users have to see the remaining 2 html pages only if they
> login in the first page.In the browser, if they give url like
>
> http://servername:8080/login.html ----It shows user login, here it goes
> to servlet program and checking the username and if it is correct user it
> chould enter second page showing the second url:
>
> http://servername:8080/folder/two.html
>
> Suppose in the browser, if i'am giving directly the 2nd url or 3rd url
> http://servername:8080/folder/two.html , then should restrict showing that
> page and should goto automatically to login page directly.
>
> Can any body help me on this immediately!!!
>
> saravanan.
> [...]
Hi :-) I don't know how to do it with three html files mentioned in your email,
but from a book(ISBN:0-471-33229-1), I find a way to do it by
Servlet+HttpSession:
0 we need two/three Servlet class: LoginServlet, worker2Servlet, worker3Servlet
1 * in doGet/doPost/service of LoginServlet:
...
HttpSession session = request.getSession(true);
... //make a obj, obj is a instance of the class you want to put in
session.putValue("SessionName", obj);
response.sendRedirect(response.encodeUrl("/servlet/worker2(3)Servlet"));
...
* in doGet/doPost/service of worker2(3)Servlet
...
HttpSession session = request.getSession(false);
if (session == null) {
response.sendRedirect(response.encodeUrl("/servlet/LoginServlet"));
return;
}
Object obj = session.getValue("SessionName");
if (obj == null) {
response.sendRedirect(response.encodeUrl("/servlet/LoginServlet"));
return;
}
// other checking, for example, check if obj is a instance of the class
// you want to put in
...
Have a nice Saturday! :-)
Bo
Nov.25, 2000
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html