Forward problem (JSP)

Discussion in 'Java' started by Raj_genius, Jan 8, 2007.

  1. Raj_genius

    Raj_genius Guest

    This is a peculiar problem..plzz i need its solution as soon as
    possible..here is my case:

    I hav a jsp page where in i have 3 combo boxes, and corresponding 3
    buttons..upon clicking each button, a javascript function is called
    which checks if the corresponding selected option in the combo box is
    valid or not..
    If valid, it forwards the end user to another page for next phase of
    actions..
    now..what my problem is, after checking/validation thru the javascript
    function, the function has to forward/move to either of 3 different
    pages..i.e
    if user clicks on button 1 and data of combo box 1 is valid then go to
    page1.jsp
    if user clicks on button 2 and data of combo box 2 is valid then go to
    page2.jsp
    if user clicks on button 3 and data of combo box 3 is valid then go to
    page3.jsp

    so..depending on whc button is clicked, the page can be forwarded to
    any of the 3 pages..
    i hav accomplished this by using location.herf within the javascript
    function and i can go to the desired page
    but the problem is that, the called jsp page(page1.jsp or page2.jsp or
    page3.jsp) cannot access the calling page's controls using
    request.getParameter(<parameter name>)

    the called jsp page can access the caller page's controls only if i use
    the submit() method in the calling page, which is not possible in my
    case as i donot hav a single/unique page to submit..i hav 3 different
    pages whc can be called..
    if i use location.herf, then the required page is loaded, but the
    called jsp page cannot access parameters using request.getparameter()
    if i use jsp:forward tag, the page is forwarded immediately when its
    loaded, without any action...

    plzz tell me a solution to this problem so that i can forward to a new
    page as well as access the caller's controls from the called jsp page...
     
    Raj_genius, Jan 8, 2007
    #1
    1. Advertising

  2. Assuming the data being submitted is not multipart, why dont you append
    the values to the location.href variable in a querystring format?

    Pretty much like var newLocation =
    '/somejsp.jsp?'+'param1='+param1+'&param2='+param2...

    -cheers,
    Manish
     
    Manish Pandit, Jan 8, 2007
    #2
    1. Advertising

  3. Raj_genius

    Raj_genius Guest

    tht wud b nice..but how to retrieve that data in the called page

    can u show in code..

    thanx 4 the reply

    Manish Pandit wrote:
    > Assuming the data being submitted is not multipart, why dont you append
    > the values to the location.href variable in a querystring format?
    >
    > Pretty much like var newLocation =
    > '/somejsp.jsp?'+'param1='+param1+'&param2='+param2...
    >
    > -cheers,
    > Manish
     
    Raj_genius, Jan 8, 2007
    #3
  4. Raj_genius wrote:
    > tht wud b nice..but how to retrieve that data in the called page
    >
    > can u show in code..
    >
    > thanx 4 the reply
    >


    <% request.getParameter("param1"); %> in a scriptlet, or
    ${param.param1} in EL.

    >From your question it appears that you need to brush up on your JSP

    syntax in general - google around and there is plenty of information
    available.

    Ideally, the routing of requests should be handled via a controller,
    and not the JSP.

    Hope this helps!

    -cheers,
    Manish
     
    Manish Pandit, Jan 8, 2007
    #4
  5. Raj_genius

    Raj_genius Guest

    thanx a lot...
    temporarity..my problem is solved...but wht if i dont want the
    parameter value to be displayed in the url..
    in this case .. i cannot use xyz.jsp?param=''

    is thr any other way ??so tht my parameter values can be hidden??


    Manish Pandit wrote:
    > Raj_genius wrote:
    > > tht wud b nice..but how to retrieve that data in the called page
    > >
    > > can u show in code..
    > >
    > > thanx 4 the reply
    > >

    >
    > <% request.getParameter("param1"); %> in a scriptlet, or
    > ${param.param1} in EL.
    >
    > >From your question it appears that you need to brush up on your JSP

    > syntax in general - google around and there is plenty of information
    > available.
    >
    > Ideally, the routing of requests should be handled via a controller,
    > and not the JSP.
    >
    > Hope this helps!
    >
    > -cheers,
    > Manish
     
    Raj_genius, Jan 8, 2007
    #5
  6. Raj_genius

    Lew Guest

    Raj_genius wrote:
    > thanx a lot...
    > temporarity..my problem is solved...but wht if i dont want the
    > parameter value to be displayed in the url..
    > in this case .. i cannot use xyz.jsp?param=''
    >
    > is thr any other way ??so tht my parameter values can be hidden??


    Set up the choice as one of several different HTML controls, e.g., submit
    buttons. Use a <form> tag, naturally, with method set to "post".

    <form name="x" method="post" action="/home">
    ...
    <input type="submit" name="destiny" value="Go to A" />
    <input type="submit" name="destiny" value="Go to B" />
    </form>

    and map the "/home" target to a controller servlet that decides where to forward:

    public class Control extends HttpServlet
    {
    protected void doPost(
    HttpServletRequest request, HttpServletResponse response )
    throws ServletException, IOException
    {
    String target;
    String destiny = request.getParameter( "destiny" );
    if ( destiny.equalsIgnoreCase( "go to a" ))
    {
    target = "A.jsp";
    }
    ....
    RequestDispatcher rd = request.getRequestDispatcher( target );
    rd.forward( request, response );
    }
    }

    Exceptions and package imports omitted for brevity.

    - Lew
     
    Lew, Jan 9, 2007
    #6
  7. Raj_genius

    Lew Guest

    Raj_genius wrote:
    >> is thr any other way ??so tht my parameter values can be hidden??


    Lew wrote:
    > Set up the choice as one of several different HTML controls, e.g.,
    > submit buttons. Use a <form> tag, naturally, with method set to "post".
    >
    > <form name="x" method="post" action="/home">
    > ...


    The action target should be "home", without the leading slash.

    - Lew
     
    Lew, Jan 10, 2007
    #7
  8. Raj_genius

    Raj_genius Guest

    Thak you lew...thts an interesting and gr8 solution, thanks...
    but here also i hav to use another new servlet/page do decide whc page
    to forward..
    but anyways..i guess i hav to pay sum price to get my work done..lol..
    thanks evry1 for replying

    - Raj
    Lew wrote:
    > Raj_genius wrote:
    > >> is thr any other way ??so tht my parameter values can be hidden??

    >
    > Lew wrote:
    > > Set up the choice as one of several different HTML controls, e.g.,
    > > submit buttons. Use a <form> tag, naturally, with method set to "post".
    > >
    > > <form name="x" method="post" action="/home">
    > > ...

    >
    > The action target should be "home", without the leading slash.
    >
    > - Lew
     
    Raj_genius, Jan 12, 2007
    #8
  9. Raj_genius

    Lew Guest

    Raj_genius wrote:
    > Thak you lew...


    Please post your replies in line with the quoted text, not on top of the
    message. The latter is called "top-posting" and makes messages harder to follow.

    - Lew
     
    Lew, Jan 13, 2007
    #9
    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. javaguy44
    Replies:
    0
    Views:
    2,665
    javaguy44
    Apr 1, 2004
  2. Matt

    JSP forward pages problem

    Matt, Jul 9, 2004, in forum: Java
    Replies:
    1
    Views:
    2,171
    Ryan Stewart
    Jul 10, 2004
  3. ohaya
    Replies:
    0
    Views:
    4,112
    ohaya
    Jun 30, 2005
  4. qazmlp
    Replies:
    1
    Views:
    615
    Jonathan Turkanis
    Feb 15, 2004
  5. Replies:
    0
    Views:
    4,440
Loading...

Share This Page