Member Avatar

Hi,

I'm trying to figure out how to pass parameters across JSP pages without using links. For some reason, I can only get null across...

Here is my code:
Page 1

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Test Page</title>
    </head>
    <body>
        <form name="testForm" action="Test.jsp">
            <select name='tableSelect' onChange='testForm.submit();' style="text-align:center">
                <option value='--Select Table--'>--Select Table--</option>
                <option value='CONFIG_SOURCE'>CONFIG_SOURCE</option>
                <option value='CONFIG_PROCESS'>CONFIG_PROCESS</option>
                <option value='CONFIG_PROCESS_SOURCE'>CONFIG_PROCESS_SOURCE</option>
                <option value='CONFIG_SAL_ROUTING'>CONFIG_SAL_ROUTING</option>
            </select>
        </form>
        <%
            out.println(request.getParameter("tableSelect"));
        %>
    </body>
</html>

Page 2:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Test Recieve Page</title>
    </head>
    <body>
        <%
            out.println(request.getParameter("tableSelect"));
        %>
    </body>
</html>

Thanks,
-Ashton

Recommended Answers

I can't see a problem with your page. Does the page submits? Does it go from page A to page B? Is the name of the Test.jsp correct and are the pages in the same folder?

Does onChange works? Should it be onchange?

Also you can try this: …

Jump to Post

All 4 Replies

I can't see a problem with your page. Does the page submits? Does it go from page A to page B? Is the name of the Test.jsp correct and are the pages in the same folder?

Does onChange works? Should it be onchange?

Also you can try this: document.testForm.submit();

Member Avatar

They're both in the same folder. I also added method="post" on Page 1... When I change the selection on Page 1, it works, and it displays what I selected, then when I refresh Page 2, it says null.

Member Avatar

Hi,

Alternatively, could you please tell me why this statement is wrong:

This is servlet code by the way...

out.println("<select name='tableSelect' onChange=form.submit(); " + request.setAttribute('currentTable', request.getParameter('tableSelect')); + "' style='text-align:center'>");

Thanks again,
-Ash

First of all request.setAttribute is void. It doesn't return a value to put it in a string.

Secondly:

They're both in the same folder. I also added method="post" on Page 1... When I change the selection on Page 1, it works, and it displays what I selected, then when I refresh Page 2, it says null.

You just said that it works. Then what is the problem? You cannot just go to a page, refresh it and expect to see data. You say you have Page1 and Page2. Which one is Test.jsp?
When you want to send data to a page you put it at the action. The request is sent to that page:

<form action="somePage.jsp" >

</form>

The data will go to somePage.jsp. This is where you put your code. That page could be even the same. It makes no difference. But the data will go only there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.