JSP Page Interaction

Reply

Join Date: Jul 2009
Posts: 81
Reputation: AshtonHogan is an unknown quantity at this point 
Solved Threads: 1
AshtonHogan AshtonHogan is offline Offline
Junior Poster in Training

JSP Page Interaction

 
0
  #1
20 Days Ago
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
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <title>Test Page</title>
  5. </head>
  6. <body>
  7. <form name="testForm" action="Test.jsp">
  8. <select name='tableSelect' onChange='testForm.submit();' style="text-align:center">
  9. <option value='--Select Table--'>--Select Table--</option>
  10. <option value='CONFIG_SOURCE'>CONFIG_SOURCE</option>
  11. <option value='CONFIG_PROCESS'>CONFIG_PROCESS</option>
  12. <option value='CONFIG_PROCESS_SOURCE'>CONFIG_PROCESS_SOURCE</option>
  13. <option value='CONFIG_SAL_ROUTING'>CONFIG_SAL_ROUTING</option>
  14. </select>
  15. </form>
  16. <%
  17. out.println(request.getParameter("tableSelect"));
  18. %>
  19. </body>
  20. </html>

Page 2:
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <title>Test Recieve Page</title>
  5. </head>
  6. <body>
  7. <%
  8. out.println(request.getParameter("tableSelect"));
  9. %>
  10. </body>
  11. </html>

Thanks,
-Ashton
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,625
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 221
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #2
20 Days Ago
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();
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 81
Reputation: AshtonHogan is an unknown quantity at this point 
Solved Threads: 1
AshtonHogan AshtonHogan is offline Offline
Junior Poster in Training
 
0
  #3
20 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 81
Reputation: AshtonHogan is an unknown quantity at this point 
Solved Threads: 1
AshtonHogan AshtonHogan is offline Offline
Junior Poster in Training
 
0
  #4
20 Days Ago
Hi,

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

This is servlet code by the way...

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

Thanks again,
-Ash
Last edited by AshtonHogan; 20 Days Ago at 9:46 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,625
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 221
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #5
20 Days Ago
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:


  1. <form action="somePage.jsp" >
  2.  
  3. </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.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply


Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC