Well, the "proper" way to do it is to only write Page2.jsp, and leave the
rest to "Form based authentication".
The action of the login form is j_security_check.
Your login html page should look like this:
<form method="post" action="j_security_check">
<input type="text" name="j_username">
<input type="password" name="j_password">
</form>
With form based authentication, you define a login and a login error html
file protecting urls (in this case your page2.jsp).
When you try to invoke page2.jsp, the container will call the login page you
specified automatically.
You find out what the user logged in as using a call to
request.getUserPrincipal() or getRemoteUser();
For a better explanation try here:
http://www.onjava.com/pub/a/onjava/2002/06/12/form.html
This does however leave you a problem as to how you are configuring your
users. You probably have 3 choices - OS authentication (probably a very bad
idea), LDAP Server or a CustomUserRegistry.
If you decide that's all too complicated for now, and you want to go with
what you have already written, then you want to have page1 stick the
username in the session, and have page2 retrieve it from the session to find
out what images to display. That way you are not passing in the username in
the request at all.
Dave Milne, Scotland
> Howdy,
>
[quoted text clipped - 56 lines]
>
> Tony
Tony - 26 Jun 2005 00:46 GMT
Dave,
Thanks for answering so quickly. You've given me quite a bit to think
about - sounds like I was barking up the wrong tree.
I'll look at changing the login stuff.
So if I put the information in the session - it is not visible to the
user if they sniff their own system nor therefore can they change it?
Thanks,
Tony
Dave Milne - 26 Jun 2005 01:20 GMT
Yes. Put simply, the way the session works is that the browser passes each
time a "session id" either in a cookie or in a parameter called jsessionid.
The App Server uses this as a key to identify a collection of data held in
the AppServer. Since the data is held on and never leaves the server
(replication between app servers aside), it isn't easily sniffable.
Check out the HttpSession documentation.
You create a session by doing myRequest.getSession(true);
You store attributes in it by doing mySession.setAttribute("key","value")
and retrieve values by doing mySession.getAttribute("key").
Dave Milne, Scotland
> Dave,
>
[quoted text clipped - 9 lines]
>
> Tony