bean instantiation and persistence question

A

Amy Johnson

I have a JSP that is a form. The form data is supposed to be stored in a
bean that I have set up as a session bean, then transfer to a servlet
for processing. The servlet then forwards to another JSP with another
form, and that goes to one of several JSPs. My problem is that, with the
bean set up as a session bean, I can't seem to get the initial JSP to
instantiate the bean. It doesn't happen until the servlet is called. Is
there something I'm doing wrong, or is there a way around this?

Thanks

Amy
 
S

Sudsy

Amy said:
I have a JSP that is a form. The form data is supposed to be stored in a
bean that I have set up as a session bean, then transfer to a servlet
for processing. The servlet then forwards to another JSP with another
form, and that goes to one of several JSPs. My problem is that, with the
bean set up as a session bean, I can't seem to get the initial JSP to
instantiate the bean. It doesn't happen until the servlet is called. Is
there something I'm doing wrong, or is there a way around this?

Check out jsp:useBean. It will create an instance in the specified scope
if it doesn't already exist.
 
A

Amy Johnson

I've done that. That's not the problem. It appears to be more geared to
the scope. If it's a session bean (which is declared in the usebean),
the introspection feature doesn't seem to work when I have the following:

<jsp:setProperty name="formID" property="*"/>

It does work however, when I have the bean scope set to request.

Any ideas?
 
S

Sudsy

Amy said:
I've done that. That's not the problem. It appears to be more geared to
the scope. If it's a session bean (which is declared in the usebean),
the introspection feature doesn't seem to work when I have the following:

<jsp:setProperty name="formID" property="*"/>

It does work however, when I have the bean scope set to request.

Any ideas?

Perhaps we need to get back to basics.
When you have an anchor which specifies a Struts action then the form
associated with that action will be instantiated when the hyperlink is
followed (clicked). The Action servlet will then forward to the JSP
according to the ActionForward returned.
If your anchor specifies the JSP itself then you can run into the
problems you seem to be describing. The solution is apparent.
For more on normal flow I would suggest an article I've written:
<http://www.sudsy.net/technology/struts-arch.html>
Note that there /are/ techniques for creating ActionForm instances
in Action servlets and making them available for subsequent JSPs,
but that implies tight coupling and knowledge of the Action which
might be invoked from forms on those subsequent pages. Perhaps not
a grave violation when the ActionForms are maintained in session
scope but still not the best way to go.
Let me know if you need clarification or examples.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top