|
Re: Why is this code not working
|
Posted: Aug 25, 2004 5:28 AM
|
|
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
|
|