You don't have to put all those ifs in the index jsp because what you are trying to do should be divided into 2 jsps.
Assuming that your first jsp is called: login.jsp. There you don't have to check if the user is logged in. All you have to do is have the login form. You can also have a message displayed if it is not null:
String message = (String)request.getAttribute("message");
if message is not null display it
- login form - with input fields and a submit button
Then submit to your login Servlet. If the user name is not correct, fill the appropriate message:
request.setAttribute("message", "Invalid username, password");
and redirect back to the login.jsp
If the username password are correct then redirect to the main page of your application (welcome page).
In there you will get the username from the session and check if it is null.
So you will not have many ifs in one page. One page for the login. One servlet for validation. Then depending on the results, go back to the login page or go to your main page
javaAddict
Nearly a Senior Poster
3,338 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 450
Skill Endorsements: 7
If you want to put them all in one jsp then you will need a lot of ifs. And you will end up with this:
if (id==1) {
// some html code
} else if (id==2) {
// some other code
}
And you will end up having a lot of different pages in one file. But you said yourself that you don't want to do that so it's up to you.
javaAddict
Nearly a Senior Poster
3,338 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 450
Skill Endorsements: 7
another way it can be done is having a lot of different div's with all their id's set (by css) to display: none;
and then, when have to be shown, have your javascript set the right id to display: block. but javaAddict is right: it'll become a huge pile of code which is very hard to maintain.
stultuske
Industrious Poster
4,493 posts since Jan 2007
Reputation Points: 1,377
Solved Threads: 630
Skill Endorsements: 25
Question Answered as of 1 Year Ago by
javaAddict
and
stultuske