Hi everyone,
I am facing a problem in my project .I am sure you'll will find a way out.I am working on a project leave management .now i am really confused as to how to go ahead.I am working with jsp and ms-access .Here the scenario is i have two types of user ,1- normal user who login and apply leaves, 2-approver who approves the leave as well as apply for leave.how can we differentiate between them.both of them should be forwarded to the same page after validation ,along with this the approver should include an extra button in the page which is only used by the approver and the normal users should not be given access to this button.how can i do this .Pls help me out with some suggestions.
thanks in advance.

if you are using directory services to differentiate users it will help you. or identify the approver by his ip address.

thanks for the reply.
But can it be done through database using his user id.And if yes then how to do it.

Just add extra column to your table to declare user groups

hi peter,
I have introduced an extra column in my master table such as

emp id password approver
1003 welcome
1004 " " 1003
1005 " " 1003
1006 " " 1003

is this the right way to do it so that i can compare them using the sql statement such as
select * from table name where approver = "emp id"
if (rs.next==true)
{
forward to this page
}
else
{
forward to this page
}

pls suggest
thanks in advance

sorry i have not placed the table properly it is like this

emp_id password approver
1003 welcome blank
1004 welcome 1003
1005 welcome 1003
1006 welcome 1003

Why did you use numeric value that is not affiliated with group description. You should always use meaningful names simple "user" and "approver" will do it nicely. As for the query this is up to you as we do not know what you are about to do.

thanks peter,
As you said if i use the simple word which is like
emp_id password emp_approver
1003 welcome approver
1004 welcome approver
1005 welcome user
1006 welcome user

then i have two normal users and two approvers so in the coding how should be the sql statement to identify that if the user has logged in as 1003 than he is the approver and should be directed to particular page.
or else i should use the same sql statement as described above.
pls suggest
thanks in advance

OK, here is query I come up with.

SELECT if(count(emp_id)=TRUE,'true','false') FROM TABLE_NAME where emp_approver="approver" and uid=LOGIN_EMP_ID;

the result of the query is BOOLEAN true or false
Simpler version would be

SELECT count(emp_id) FROM TABLE_NAME where emp_approver="approver" and uid=LOGIN_EMP_ID;

the output is numeric value zero or one, if you get value larger then one something wrong with your table as I expect emp_id to unique.

hi peter,
SELECT count(*) FROM employee_details WHERE emp_approver="approver" AND uid=LOGIN_EMP_ID;
As you have given me the sql statement to differentiate between users i wanted to know that what i need to place in (uid=LOGIN_EMP_ID).Is it the emp_id no or the person who is entering the emp_id such as the string value.
pls suggest
There is one more problem i have come accross,which is in reset password.will talk about this later as soon as this query is resolved.

thanks in advance.

LOGIN_EMP_ID is the emp_id on login submitted on login process, which you retrive from the login page compare with database for authentication and see what that person in the system in order to provided with appropriate user view

thanks for the reply,
i will try out this code and let you know about it. i do have one more query, if the current query is solved than should i write in this same post or another.

I had second thought in regards of current problem. The query currently satisfies the need of checking user group assignment however it does not check if the user is authenticated. Meaning we did not check if user name and password are correct. Therefore you either have to run first query first query that will check login details and then second query as discussed above, or just have one query as

select emp_approver from TABLE_NAME where emp_id=LOGIN_EMP_ID and password=LOGIN_PASSWORD

This will return a value if login details are correct and you can use this value in your servlet to determinate which view to display. It was my mistake to concentrating on "does the user belong to this or that group".

As for the question about posting. If current problem solved, you should create new thread. (Also would be nice if you mark this post as solved, to let know others that you got your solution)

thanks peter,
that is fine.now going ahead i have set the approver a different page and the user a different page,but when i have to apply for leave, which both user and approver has to do. they both are forwarded to same page i.e leave_apply.jsp even that is succesfully happening but when i come back pressing the back button how will i get him to the particular session.
pls suggest.

After pressing leave you want to direct them to small servlet that will destroy previously created session and then forward them to final page. Therefore your pages after successful login should check for validity of session.

hi peter,
i have created sessions and as you said that the previously created sessions has to be destroyed,if i do that then how can i go back to my main page i.e the page after login which is the main page for the particular user.i dont want him to completely come out or direct him to particular page.what i have to do is two users with two different pages and in both the pages there is one link to the same jsp page so for coming back i have written
<FORM ACTION="welcome.jsp" method="post" >
<button type="submit"><-- back</button></center></form> for a particular user but the approver main page name is welcome1.jsp,so if approver logs in and apply leave from the same jsp page then how can i direct him back to the main page. i cannot use <INPUT type="button" value="Back" onclick="history.back()">because clicking the back buton i dont want him to go to the apply form page else i want him to be directed to his main page .please give a solution for this problem.if any other way is there then suggest me.
thanks in advance.

LOL, this is mess. From leave I understood that you want to create logout process that is why I said to destroy sessions. If it is not case of logout process simply direct both pages to servlet that will process request, update sessions values and depending on user group direct to relevant page you need it to go. The flow can be like

login->login servlet->main page for user(user will pick form submission)->form page->validation servlet(validate form, update session, redirect)->main page for user

Is that what you trying to achieve?

hi peter,
yes this is what i wanted to achieve.but could you help me out with the validation servlet bcz as i said there are two different pages for user and approver.so according to the flow if he is redirected to main page he should use response.setRedirect("the page name"); but i have two pages right so how it is going to identify which page to send back.If any example code is available pls send and help me out with this problem.
thanks in advance.

Option one

String url = request.getRequestURL().toString();
System.out.println("Request from = " + url);

Will return something like this
Request from = http://localhost:8080/daniwebtutorial/login.jsp

Option two
Use the session to pass user group details along the process. In the validation servlet you will retrieve the session, check for user group and redirect base on that

thanks peter,
I tried it and it is successfully giving me the results which i need.I dont know how to thank you.You did a wonderful job.
thanks once again.
As i said i have a query with reset password i am closing this thread and opening a new thread and i am sure you will help me out.

Bring it on ;)

Just clearly state your intentions so we can avoid previous mistakes of side tracking (partially my mistake too)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.