facebook

Need a direct way to pass a single dynamic parameter to JSP?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #224470 Reply

    ajs
    Member

    Is there a simple and straightforward way with Struts to pass a single dynamically generated parameter from one JSP page to another JSP page?

    As an example –
    We have a jsp page listing customer orders and we want to link from a single order in the list to a page showing just that one order with all the details. The link would pass a variable order number.

    Conceptually the link should be the equivalent of

    /singleOrder.jsp?orderNum=18472  

    (which of course doesn’t work).
    And the link could be created with something like

    <html:link forward="toSingleOrder" paramId="orderNum" value="<%=orderNumber[x]%>">order details</html:link>

    Finally the retrieval of the order number in singleOrder.jsp could be something like

    String orderNo = request.getParameter("orderNum").toString();

    All the info found on this matter via google has seemed to be convoluted or obscure and lacks specific examples. Any help on this would be much appreciated.

    – System Setup ——————————-
    Operating System: Win 2K
    Eclipse version: 3.0.1
    Eclipse build id: 3.8.3
    Fresh Eclipse install
    No other installed external plugins

    #224492 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft dev, this isn’t MyEclipse related.

    #224493 Reply

    Riyad Kalla
    Member

    /singleOrder.jsp?orderNum=18472

    Why doesn’t this work? Is there another request/response cycle between the two JSPs that looses the query string?

    #224582 Reply

    ajs
    Member

    Thanks for the response.

    There should be nothing between the two jsps – unless Struts is adding something.

    I thought

    /singleOrder.jsp?orderNum=18472 

    should work, but in singleOrder.jsp there seemed no way to find orderNum, so I am assuming it can’t be passed this way.

    I am open to trying anything that might make this direct approach work.

    #224583 Reply

    Riyad Kalla
    Member

    should work, but in singleOrder.jsp there seemed no way to find orderNum, so I am assuming it can’t be passed this way.

    This *is* fine to do, it a standard query string parameter. You should be able to use the request.getParameter(String), request.getParameters(String), request.getParameterMap, etc. methods to retrieve this value.

    If you were trying to use the getAttribute methods, then that is likely why you weren’t getting anything returned. The ‘attribute’ fields are hashstables that can be used to set/get values that are passed from the application level back and forth… the ‘parameter’ values are from POST/GET operations to your pages from the client.

    #224586 Reply

    ajs
    Member

    In singleOrder.jsp I used

     String orderNum = request.getParameter("orderNum").toString();

    but this generates a NullPointerException in the _jsp.java

    #224597 Reply

    Riyad Kalla
    Member

    Here is a sample project that submits a value from a link and a form to a page that prints the value out. Compare it to yours and see what might be going wrong (make sure you didn’t map the struts servlet to *.jsp or something like that)

    Attachments:
    You must be logged in to view attached files.
    #224608 Reply

    ajs
    Member

    Did you miss adding a link or an attachement to your answer?

    Thanks.
    Alan

    #224609 Reply

    ajs
    Member

    Now I see it.
    Thanks.

    #226874 Reply

    flamesnm
    Member

    Hi

    Could I piggyback on this thread as I’m having the same problem. It should be simple 😳

    I’m linking from a static HTML page to a .jsp with :
    <INPUT type=”button” value=”start”
    onclick=”window.open (‘http://172.19.15.167:9080/MailDatabase/mailin.jsp?appName=colour‘, ‘newwindow’, config=’height=400,width=314, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no’)”></form>

    However, I get a null value from the request with :
    String appCode = request.getParameter(“appName”);
    contact.setAppCode(appCode);

    When I view the request through debug all the parameter in the action form are present in the request, but the appName parameter doesn’t appear.

    Regards

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: Need a direct way to pass a single dynamic parameter to JSP?

You must be logged in to post in the forum log in