The Artima Developer Community
Sponsored Link

Java Answers Forum
Why is this code not working

5 replies on 1 page. Most recent reply: Aug 25, 2004 5:28 AM by Lebo Makoloko

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Lebo Makoloko

Posts: 3
Nickname: kgabutle
Registered: Aug, 2004

Why is this code not working Posted: Aug 23, 2004 1:38 AM
Reply to this message Reply
Advertisement
In JSP

<%user = EventsUser)session.getAttribute("EventsUser"); out.println(user.getUserName()); %>

In Servlet

eventsSession.setAttribute("eventsUser", eventsUser);

What I am trying to do is to store a User bean in HttSession in the servlet, then retrieve it (User bean) in the JSP. I get a class not found (EventsUser) error when running the JSP.

(Formatting this post did not work for me)

Kgabutle


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Why is this code not working Posted: Aug 23, 2004 1:48 AM
Reply to this message Reply
May be becuase you are setting as "eventsUser" and trying to get it as "EventsUser". Case sensitivity I guess.

Lebo Makoloko

Posts: 3
Nickname: kgabutle
Registered: Aug, 2004

Re: Why is this code not working Posted: Aug 23, 2004 2:34 AM
Reply to this message Reply
Sorry, that was a typing mistake on my part when I created the post. The correct code should have been "eventsUser". Even after this correction, the error is still there.

Kgabutle

Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Why is this code not working Posted: Aug 23, 2004 10:55 PM
Reply to this message Reply
> Sorry, that was a typing mistake on my part when I created
> the post. The correct code should have been "eventsUser".
> Even after this correction, the error is still there.
>
> Kgabutle


What is the error?

Benjamin Armintor

Posts: 2
Nickname: benjamin
Registered: Jun, 2004

Re: Why is this code not working Posted: Aug 24, 2004 12:09 PM
Reply to this message Reply
Did you import the EventsUser class in your JSP?

Lebo Makoloko

Posts: 3
Nickname: kgabutle
Registered: Aug, 2004

Re: Why is this code not working Posted: Aug 25, 2004 5:28 AM
Reply to this message Reply
Yes I did. Just to give a bit more data on my problem, when I used Struts to create a webapp, this is what I did to share data between a jsp and an action. In the action, I created a form and filled it with details. Then I stored that form in a session.

In the jsp, I retrieved the form using similar syntax to the one I mentioned in my original question and retrieved my form from the session. Here I am using plain jsp and a servlet. What I am not sure of is whether following the same Struts principle in sharing data between a jsp and servlet would produce the same result. It looks like it does not and I am not sure whether my problem is syntactical or the plain jsp/servlet way of sharing code is different.

The essence of what I trying to do is:
1. Create a bean
2. Populate it with some data
3. Obtain an instance of HttpSession and store the bean in it
4. Forward to a jsp using the RequestDispatcher's forward method
5. In the jsp, retrieve the saved bean from the session
6. Then of course use the data.

Below is the code that is giving me problems:

In JSP
<jsp:useBean id="user" scope="session" class="App.EventsUser"/>
<%user= (EventsUser)session.getAttribute("eventsUser"); %>

In Servlet
//1. get instance of session
//2. create and populate userBean
//then
HttpSession eventsSession = request.getSession(true);
EventsUser eventsUser = new EventsUser();
eventsUser.setUserName(request.getParameter("username"));
eventsUser.setPassword(request.getParameter("password"));
eventsSession.setAttribute("eventsUser", eventsUser); 


I have not worked on this for the last two days and that's why I was not responding to feedback from you guys. Thanks in advance for all the people who are and will be helping me.

Lebo

Flat View: This topic has 5 replies on 1 page
Topic: sorting files according to the date in there filename Previous Topic   Next Topic Topic: Java Files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use