Forums Register Login

Beans and Jsps and Servlets

+Pie Number of slices to send: Send
Hello all....
If someone could help me with this it would be GREATLY appreciated.
I have a web application that makes use of beans and jsps and servlets.
My problem is this...
I <usebean> on my initial JSP and have one user input field. My action on the Form is to go to a Process Jsp page which basically does a <set property> and then forwards to a servlet that uses the input field to look up a database record. I then fill up the bean with the setter methods and then forward to a display JSP page.
I am using the getAttribute in the servlet to get the bean and I am using getRequestDispatcher.forward for the JSPs. And when I <usebean> I am using request scope.
Problem is that as I am moving from page to page to servlet etc. I am losing my Bean data.
It only seems to be happening if I need to use two forms. I have page one is a form which processes the info and forwards to page 2 which is another form. When I process, I have already lost my bean and the information from page 1.
I just don't get it!!! I have been researching this all day and it seems like a SIMPLE THING but it is just not working for me. Is my request being lost somewhere???
All I can think of is that when I POST a form I am getting a NEW request at that time???
ANY help on this would be appreciated!!!
+Pie Number of slices to send: Send
Jennifer
Can we see your code? What scope did you give the bean?
Also, check out the naming policy here at the ranch. You need to change your display name to be a first name a space and last name.
Thanks.
+Pie Number of slices to send: Send
thanks for the quick response
I did give the bean request scope.
containerInquiry.jsp -
<jsp:useBean id='ContainerBean' scope='request' class='csp.beans.ContainerBean'/>
<form action='equipment-process-page'>
<input type='text'
name='equipment'
value='<%= ContainerBean.getEquipment()%>'>
<input type='submit'>
</form>
Which then submits to
equipment-process-page.jsp -
<jsp:useBean id='ContainerBean' scope='request' class='csp.beans.ContainerBean'/>
<jsp:setProperty name='ContainerBean' property='*'/>
</jsp:useBean>
<jsp:forward page='query-equipment-action.do'/>
which forwards to a servlet
queryEquipment.java -
ContainerBean containerBean = (ContainerBean)req.getAttribute("ContainerBean");
if(containerBean == null){
containerBean = new ContainerBean();
req.setAttribute("ContainerBean", containerBean);
}
Servlet also fills up a bunch of fields based on the input from the containerInquiry.jsp
**then forwards to another form page**
servlet.getServletContext().getRequestDispatcher(res.encodeURL(url)).forward(req, res);
entryEquipment.jsp -
At this point its almost like starting the cycle again. This page contains a form that the user enters in data and posts.....gets forwarded to the SAME process page above and the same servlet (which checks some parameters)..
The problem is this time around I need the data that was stored in the bean from the FIRST time around...
I hope I am explaining myself clearly...
Thanks!!!
+Pie Number of slices to send: Send
Hey Jennifer
Thanks for fixing your name.
The first thing that jumps out at me is that you'll lose the bean you create in your containerInquiry.jsp page. That bean has request scope so once the response is sent to the browser and the user clicks submit then they are starting a new request. The next two pages forward the request sot he bean would persist but then the entryEquipment.jsp page has a form that the client filss out. This means that a response is sent back to the client and a new request is going to start when they submit the new form.
If you want to make data persist over multiple requests then change the bean's scope to session or use the session state to save info between requests.
Hope that helps
+Pie Number of slices to send: Send
Thanks Dave....
Your help is much appreciated. I am going to change the bean scope to session.
I'll post back if I have any further problems...
Jennifer
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1399 times.
Similar Threads
Struts validation problem..
Infinate loop between JSP and Servlet - getParameter scope appears to be indefinate
Bean Disscussion
problems with action mapping
usebean getProperty and setProperty in the same form field
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:37:02.