maintaining state between JSPs going through servlet

B

Brett Cramer

This is probably considered a common issue, but maybe our dictated
design and architecture guidelines make it a little bit unique, who
knows. And also let me preface this with the fact that I am
relatively new to Java having been a VB programmer for 10 years. :D

We have a JSP application that uses one main servlet to access an
Oracle 9i database. The screen we are working on has many fields for
the user to fill out, and some of the fields are populated by
performing "lookups" to the database since they represent a list of
possible values (example, a bank name is looked up and it's address
and other details are returned).

The design dictated to us was for the user to either key in a keyword
for a bank name search, or choose from a list of sub-accounts which is
populated based on an initial account selection. We wanted to do a
pop-up style window to allow this search and to display the results,
and then the user would choose one and then return to the original
calling JSP page and fill in the apropriate fields based on what they
chose in the popup. Well, we cannot use a popup because we have to
use a prebuilt Navigation object which always puts the left menu and
borders on every page called using the object. So we decided to just
forward the user to the search page, leaving the original page to do
the search. This presents a state problem since the information on
the original page must be preserved because the user is going to
eventually come back to it. I thought, no sweat, just use some
session vars right? However, the user clicks a "Search" button and it
then calls the submit for the search form. The request does not
contain the values for the original calling screen, so I can't set my
session vars at that time. I am not sure if we should try setting the
session vars in the JSP instead or not. I am one doing the servlet
stuff while another person is doing the JSP. I am not sure where to
put more of the "responsibility" of state management--JSP or servlet.

Without asking for a specific solution (because I know it's not the
best design, but we have no choice) what options do I have in
creatively and efficiently maintaining state? At the root of this
issue is basically how to perform searches on one screen and allow the
"root" screen to maintain all of its values while receiving new values
from the search the user did. I am starting to think that leaving the
root screen is not the best option, but the popup can't be used. I'm
stumped.
 
J

John C. Bollinger

Brett said:
This is probably considered a common issue, but maybe our dictated
design and architecture guidelines make it a little bit unique, who
knows. And also let me preface this with the fact that I am
relatively new to Java having been a VB programmer for 10 years. :D

We have a JSP application that uses one main servlet to access an
Oracle 9i database. The screen we are working on has many fields for
the user to fill out, and some of the fields are populated by
performing "lookups" to the database since they represent a list of
possible values (example, a bank name is looked up and it's address
and other details are returned).

The design dictated to us was for the user to either key in a keyword
for a bank name search, or choose from a list of sub-accounts which is
populated based on an initial account selection. We wanted to do a
pop-up style window to allow this search and to display the results,
and then the user would choose one and then return to the original
calling JSP page and fill in the apropriate fields based on what they
chose in the popup. Well, we cannot use a popup because we have to
use a prebuilt Navigation object which always puts the left menu and
borders on every page called using the object. So we decided to just
forward the user to the search page, leaving the original page to do
the search. This presents a state problem since the information on
the original page must be preserved because the user is going to
eventually come back to it. I thought, no sweat, just use some
session vars right? However, the user clicks a "Search" button and it
then calls the submit for the search form. The request does not
contain the values for the original calling screen, so I can't set my
session vars at that time. I am not sure if we should try setting the
session vars in the JSP instead or not. I am one doing the servlet
stuff while another person is doing the JSP. I am not sure where to
put more of the "responsibility" of state management--JSP or servlet.

Without asking for a specific solution (because I know it's not the
best design, but we have no choice) what options do I have in
creatively and efficiently maintaining state? At the root of this
issue is basically how to perform searches on one screen and allow the
"root" screen to maintain all of its values while receiving new values
from the search the user did. I am starting to think that leaving the
root screen is not the best option, but the popup can't be used. I'm
stumped.

(1) Remember that by the time the page gets to the client it is a plain
HTML page (apologies if this is too basic). Some web programmers get
hung up on the provenance of the HTML -- JSP, servlet, static, etc. --
and are confused about what they can and can't do on the client side.

(2) As the converse of (1), anything you want your JSP to do, it must do
between receiving a client request and sending the corresponding response.

(3) It is not clear to me why use of your Navigation object precludes
popups. What is the requirement for the popups that you don't think you
can achieve?

(4) Assuming that you proceed according to your revised plan, this is
mostly an HTML problem (see also (1) above). Some things that might be
useful for you to know if you don't already:
(a) A form can have multiple, distinguishable submission buttons
(b) When you submit an HTML form only that form's fields are submitted
(i.e. not any fields in any other form on the same page)
(c) You can put client-side active content in the HTML (e.g.
Javascript, applets, ActiveX controls, etc.)

(5) If you are going to have the user navigate through a series of
screens then there is no good alternative to making him submit any data
he enters as part of the next navigation request. The webapp must pick
it out of the request and either store it on the server side, or reflect
it back to the client in the response in manner that allows the cycle to
repeat.

(6) If you use popups then you can maintain state in the root page until
the user is ready to submit the completed form.


I hope some of that helps.

John Bollinger
(e-mail address removed)
 
B

Brett Cramer

John C. Bollinger said:
(1) Remember that by the time the page gets to the client it is a plain
HTML page (apologies if this is too basic). Some web programmers get
hung up on the provenance of the HTML -- JSP, servlet, static, etc. --
and are confused about what they can and can't do on the client side.

(2) As the converse of (1), anything you want your JSP to do, it must do
between receiving a client request and sending the corresponding response.

(3) It is not clear to me why use of your Navigation object precludes
popups. What is the requirement for the popups that you don't think you
can achieve?

(4) Assuming that you proceed according to your revised plan, this is
mostly an HTML problem (see also (1) above). Some things that might be
useful for you to know if you don't already:
(a) A form can have multiple, distinguishable submission buttons
(b) When you submit an HTML form only that form's fields are submitted
(i.e. not any fields in any other form on the same page)
(c) You can put client-side active content in the HTML (e.g.
Javascript, applets, ActiveX controls, etc.)

(5) If you are going to have the user navigate through a series of
screens then there is no good alternative to making him submit any data
he enters as part of the next navigation request. The webapp must pick
it out of the request and either store it on the server side, or reflect
it back to the client in the response in manner that allows the cycle to
repeat.

(6) If you use popups then you can maintain state in the root page until
the user is ready to submit the completed form.


I hope some of that helps.

John Bollinger
(e-mail address removed)


We found some JavaScript that might be able to help us with this:

http://www16.brinkster.com/rajspace/ViewStateMagic.html
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top