aspose file tools*
The moose likes Servlets and the fly likes login/logout link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "login/logout link" Watch "login/logout link" New topic
Author

login/logout link

Mark Moore
Greenhorn

Joined: Feb 21, 2006
Posts: 15
I have a javascript that returns null if a cookie is not present:

I would like to use this script to put on all my html pages a link to: LOGIN
or a link to LOGOUT, (if script returns NULL then the link to Login should be shown otherwise link to logout is shown on HTML page)

I don't know how to go about this,

Mark
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Are you sure you want to be doing this in Javascript? It's much more appropriate to handle this sort of thing on the server...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bruno Boehr
Greenhorn

Joined: Feb 15, 2006
Posts: 17
Such functionality can be easily implemented on the server side, and it will be in many ways a better solution than doing that in-browser, because:

- it will work regardless of whether the browser supports JavaScript;

- you won't have to deal with cross-browser compatibility issues;

- the server has access to a lot more information than is available to the script through cookies; for example, you could provide more links to personalized things like the user profile page, his/her unread messages and what not.

Anyhow, I do not see why anyone would want to employ JavaScript when all this is easily doable via server-side logic. Or am I missing something here?


<a href="http://webjavenue.com/" target="_blank" rel="nofollow">Your first website in Java: easier than you think</a>
Mark Moore
Greenhorn

Joined: Feb 21, 2006
Posts: 15
I am looking to make dynamic text in javascripts:
set content of a <DIV> to login if cookie is null or logout if cookie is not null

not sure how to go about it
[ February 23, 2006: Message edited by: Mark Moore ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

As Bear has stated, containers have server-side functionality implemented that can manage much of this for you, we do not recommend doing it in JavaScript on the client.

If you want to look at the container managed authentication, have a look at FORM based authentication, available in any good J2EE servlet container. If you would still like to do it using JavaScript you can ask a question in the HTML/JS forum or we can move the thread there for you.

Dave
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Mark Moore:
I am looking to make dynamic text in javascripts:
set content of a <DIV> to login if cookie is null or logout if cookie is not null

not sure how to go about it


If you're adamant about doing this in Javascript, then you may want to request that this be moved to the HTML/Javascript forum where the Javascript gurus hang out.
Let us know.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: login/logout link