Display record from database based on User Logged in using DAO Pattern and Servlets.

Hello Everyone! A new thread i have started and this is how the problem goes...

I want to display record of a user something like profile details based on the user who has logged in to member's page! So when the user has logged in and clicks on the view profile details link it should take to the profile.jsp and display the details of the user who has logged in to the member's page.

hy anand! thanks for the reply but im using the DAO (Data Access Object) pattern for display of record! MVC is not part of my requirement! cud u suggest me an idea of how to use it! I have a DAO.java file and i knw sessions in the servlet has to be implemented to show the record!

Yes Peter i cn! All Code should be in a DAO File such as Database Connection and the SQL Statements and the records should be called in the JSP whilst nt having the Database Code in the JSP! Servlets should nt also contain any database code as previously mentioned as it is a violation of DAO.

The MVC Model (Model View Controller) pattern acts more like being able to handle several requests from the user and dispatch them to the respective servlet! An Example would be a Relay Servlet being able to Dispatch the request to a servlet based on a hidden field from the Java Server Page!.

DAO is simply acting as a layer where all code for the database is in a java file and has to be called in servlets! Methods are called in servlet so that is how my system should act! Cud u assist me with a logic at least? I would really appreciate your thanks.

THANK U !

I MUST SAY! IT IS GREAT TO BE PART OF THIS COMMUNITY AS I AM GETTING TO LEARN ALOT!

You have already written the code at your previous thread. Click the link that goes to the profile.jsp, call the method that gets the data and display them.
Pass as argument to the method the username. When you login, put the username in the session and get it at that page.

When the user logs in:

session.setAttribute("USER_NAME", user_name_value);

When the user logs out:

session.setAttribute("USER_NAME", null);

Whenever you need the username take it:

String userName = (String)session.getAttribute("USER_NAME");

If the userName is null then no one is logged in. You need to put that in an if statement and redirect to the login page if the username taken from the session is null

And since you have written all that code in the previous thread this should be very easy, because you already go to a page, run a DAO method and display.

And what you have described is the MVC. And it is not like: "MVC is not in my requirements" because it is not something someone asks you not to do. It's a "way" of solving things which you can follow. And that link provided has a very good example of how you should do things.
But that is only an example. If you want to learn JSP, you need to study from a book or a tutorial. Not rely solely on examples and scrip-lets of code taken from here

Hy friend! i used the same method as per in the previous thread! Calling the array list from the DAO.java in to the JSP Everything! The only issue encountered is that it refuses to accept the Username as a parameter in the method! Since in the previous thread the counter was of integer variable , in this the Username is a string and it is what we are passing as a paramter!

String Username = (String)session.getAttribute("Username");
session.setAttribute("Username", Username);
OshwalDAO dao = DAO.getDAOInterface();
ArrayList GetLoggedInUser = dao.GetLoggedInUser();
if(Username!=null)
{
BorrowerRecordViews Borrower = (BorrowerRecordViews)GetLoggedInUser.get(Username);
//Here is the Method GetLoggedInUser equal to the method of dao.GetLoggedInUser(). The Parameter as u cn see is the Username and is refusing to accept the Username because it can only accept the Integer variable as a parameter.
}

Then pass as parameter the integer that it needs. I don't know your code to tell you what to pass and how. I told you the methodology.
Call the method that returns the data that you need and display them.
Now you have to think and make the neccassary changes.

Also: I assume that when you get the username from the session you had put it there when you logged in. It doesn't automicaly gets there

If the method takes as argument an int then put in the session the int that you need and take that when you call the method. If you don't have access to that int change the method to take as parameter the username instead of the int.

GetLoggedInUser is a list. Why do you cast it to BorrowerRecordViews ?
Also you wrote the code for the GetLoggedInUser method, right? Then I don't see what is the problem. You should know how to call it and what to do with the results, since you wrote the implementation: You put BorrowerRecordViews objects in the list that you return That is the solution to your problem

If you are having problems then I would suggest going back to your notes and study how to call methods, and how to use generics and lists.

Hy Friend! Sorry for late reply! Have been busy trying to figure out how to Come up with a solution! In the previous post i had used the same way to project the records of a borrower in the same way as i have shown here with only the difference of the Paramter being passed.! In the previous post i had!