cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving User in JSP page?

Former Member
0 Kudos

The goal is to simply access the logged in user's information from a JSP page.

What we've done so far is setup an application on Basic Authentication. We deployed a simple JSP "application" with the Authentication. When we hit it, we get a logon prompt. So far so good.

Now the only problem is, I've been trying to retrieve the user information with the IUserFactory. However, I'm getting exceptions when I use them. I'm not sure if using the I* interfaces are acceptable in a simple JSP page so that's what I wanted to know.

Is my whole attempt in retrieving the IUser in a simple JSP incorrect or must I use a servlet or another component?

Thanks,

David

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

It is not necessary to use a servlet for this purpose.

But a simple java class with the variable for user details to be stored is enough.

1. create an object of the class and store the user information to this object(when user is logging initially)

2. Bind this object to the current Session.

HttpSession ses = request.getSession();

ses.setAttribute("someName",objectToBind);

3. Retrive the binded object and get the user info.

// in jsp latter when user details is needed.

userobj = ses.getAttribute("someName");

<jsp:useBean id="user" class="userobj" />

4. Now you can get the user information ...

thanks and regards,

arul sekar

Former Member
0 Kudos

From the replies, I'm assuming that I can't use ONLY a JSP page then? We are currently just testing

using the Basic JRAAuthentication so it gives us a windows prompt for user / pw; we did not create

our own HTML login form. Only a simply JSP page. Here is what I have tried:

<% IUser user = componentRequest.getUser();    %>
Hello, <%= user.getFirstName() %>

And I get a 500 error with this message:

Application error occurred during the request procession. 
  Details:   com.sap.engine.services.servlets_jsp.server.exceptions.WebIOException:
  Error compiling [/UserLoginApp/login.jsp] in application [UserLoginApp].  The ID of this error is 
Exception id: [001321FBCE1F00470000008B0000032000040E6B2E5D2B08].

It appears that perhaps I do need to make my own login page along with my own customized login

module to add the user to the session? I'm surprised that I would have to do that and the existing

login modules don't already do that?

David

Former Member
0 Kudos

Hi David,

try this code in your JSP:


<%
IUser user;
user= UMFactory.getAuthenticator().getLoggedInUser(request, response);
%>

You should receive the current user.

Best regards,

Stefan Brauneis

Former Member
0 Kudos

Stefan,

Thanks! That was exactly what I needed.

I really have no idea how you guys figure out these things. I can't find APIs anywhere to explain what and how things work.

David

Former Member
0 Kudos

Hi,

From where do I get the request, response objects? Can you post a sample code?

For this do I have to have to import any class, or do I use the implicit request and response?

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

<b>Login and retrieve user data from database :</b>

Tha following will have sample code for login and retrieve user data.

http://www.daniweb.com/techtalkforums/nextnewesttothread35732.html

FOr more details on JSP to retrieve data, ple go thru it.

http://www.weblogic.com/docs/examples/jsp/index.html

http://java.sun.com/developer/technicalArticles/Programming/jsp/

HoPE It HElPS ... !!!

Thanks

VArun CN

Former Member
0 Kudos

David,

If you can provide more information on the types of errors / exceptions you are getting it would be helpful in guessing your problem.

<b>[The goal is to simply access the logged in user's information from a JSP page.]</b>

You can achieve this by putting a user information object in the session object. The general flow would be

1. Login page display. User enters credentials , clicks on logon button.

2. The authentication module is called.This verifies user credentials and then creates a new session for the user.Puts the information relevant to the current user in the session.Forwards the request to the page which displays the details after successful logon.

3. This page retrieves the details of user from session and displays it.

Hope this helps.

~ Amol