JSP - saving textfield values before loading 'intermediate' page

Discussion in 'Java' started by Rico, Mar 13, 2005.

  1. Rico

    Rico Guest

    Here's the scenario:

    We have a JSP page that takes user's input to produce a document.
    The user would need to upload an attachment for the document.
    The upload is performed by a servlet, which causes us to leave the current
    page of input. But we want to preserve the data the user has already input
    in the textfields.

    So, we're looking at using the session scope. What is the best way to save
    the values already input to a session Object before calling the upload
    servlet?
    I'm thinking most parameters on the JSP page have no business being in the
    upload servlet and it'd be messy to get it to save said parameters.

    I'm just wondering whether I'd be reinventing the wheel, or have the wrong
    conception, because preserving state is a 'standard' aspect of web
    programming. My idea is to have a dedicated helper servlet that would
    perform this task of saving the parameters already input to the session
    Object before redirecting us to the upload page.

    Is there a simpler way?

    Rico.
     
    Rico, Mar 13, 2005
    #1
    1. Advertising

  2. Rico

    kaeli Guest

    kaeli, Mar 14, 2005
    #2
    1. Advertising

  3. Rico

    Rico Guest

    On Mon, 14 Mar 2005 07:32:18 -0600, kaeli wrote:
    > In article <>,
    > enlightened us with...
    >>
    >> So, we're looking at using the session scope. What is the best way to save
    >> the values already input to a session Object before calling the upload
    >> servlet?

    >
    > A bean with session scope.


    Thanks.
    More specifically, my question is how do I save the textfield values
    present into the fields of the bean.
    Is a request mandatory?
    If so, should the task be delegated to the next page where some parameters
    might not have any business being at all, if only for being 'saved'
    or do I need a dedicated servlet for the purpose of saving parameters and
    afterwards calling the required following page?

    Is something like
    sessionBean.setProductID(request.getParameter("productId"))
    the only (best?) way to commit textfield values to the session?

    Rico.
     
    Rico, Mar 14, 2005
    #3
  4. Rico wrote:

    > Thanks.
    > More specifically, my question is how do I save the textfield values
    > present into the fields of the bean.
    > Is a request mandatory?


    well, a request is needed to get the session. Anyway, I don't see the
    problem. You always get a request for free.


    > If so, should the task be delegated to the next page where some parameters
    > might not have any business being at all, if only for being 'saved'
    > or do I need a dedicated servlet for the purpose of saving parameters and
    > afterwards calling the required following page?


    if you want to save them in the next page, you will have to use forward.
    If you use redirect you will reach the next page without parameters.
    Even using forward you will have to save the parameters in the form as
    hidden values, or build some logic in the jsp code to save them when the
    page is loaded. To be short: don't save them in the next page.
    Besides, it makes sense that the first page, with the first form, has a
    servlet that takes care of it. You can (and maybe should) use a session
    bean to store the data for more servlets, but let each servlet save its
    own part.

    >
    > Is something like
    > sessionBean.setProductID(request.getParameter("productId"))
    > the only (best?) way to commit textfield values to the session?


    Something like that, yes

    I would also like to comment that using a session bean is not always the
    best way. You might get into troubles if the user can edit two forms at
    the same time. That also depends on how your requirements are.
     
    Andrea Desole, Mar 14, 2005
    #4
  5. Rico

    kaeli Guest

    In article <>,
    enlightened us with...
    > More specifically, my question is how do I save the textfield values
    > present into the fields of the bean.
    > Is a request mandatory?


    Yes. The form is on the client. To get the values on the server, a request
    must be issued.
    How that is accomplished is highly dependent on what you're trying to do.
    For example, if the user initiates a "save" type deal, they can just press a
    form submit button that submits to a JSP page that has a bean set up with the
    proper matching setters for each field.
    If you're trying to do this independent of user action, you have a few
    options, all of which are prone to failure. ;)
    Or they require javascript on the client, which has its own pitfalls.

    I assume the values you want saved are values the user changed AFTER the page
    was rendered and sent to the client. If not, this is all a moot point. Just
    save them before you render the page.

    > If so, should the task be delegated to the next page where some parameters
    > might not have any business being at all, if only for being 'saved'
    > or do I need a dedicated servlet for the purpose of saving parameters and
    > afterwards calling the required following page?


    If this is typical of your application, you should be using an MVC
    architecture and have a controlling servlet do all that work. That would be
    similar to your latter choice above.
    If this is a one shot deal, just save them in an intermediate page and
    forward on the request.

    Do keep in mind that a user more than likely can have two browsers, and thus
    two sessions, open at the same time. All web apps should be written with this
    in mind.

    --
    --
    ~kaeli~
    Persons disagreeing with facts are always emotional and
    employ faulty reasoning.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Mar 14, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    1
    Views:
    1,593
    Tomer Ben-David
    Oct 27, 2004
  2. Topi
    Replies:
    6
    Views:
    904
    Brian Drummond
    May 6, 2011
  3. Filiz Duman

    SUM TEXTFIELD VALUES

    Filiz Duman, Jan 12, 2004, in forum: Javascript
    Replies:
    1
    Views:
    101
    Randy Webb
    Jan 12, 2004
  4. bhabs
    Replies:
    2
    Views:
    450
    Tad J McClellan
    Feb 13, 2008
  5. Husain
    Replies:
    3
    Views:
    200
    Thomas 'PointedEars' Lahn
    Apr 14, 2008
Loading...

Share This Page