944,080 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 2080
  • JSP RSS
Nov 3rd, 2009
0

JSP Page Interaction

Expand Post »
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
JSP Syntax (Toggle Plain Text)
  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:
JSP Syntax (Toggle Plain Text)
  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
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
AshtonHogan is offline Offline
209 posts
since Jul 2009
Nov 3rd, 2009
0
Re: JSP Page Interaction
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();
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,260 posts
since Dec 2007
Nov 3rd, 2009
0
Re: JSP Page Interaction
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.
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
AshtonHogan is offline Offline
209 posts
since Jul 2009
Nov 3rd, 2009
0
Re: JSP Page Interaction
Hi,

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

This is servlet code by the way...

JSP Syntax (Toggle Plain Text)
  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; Nov 3rd, 2009 at 9:46 am.
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
AshtonHogan is offline Offline
209 posts
since Jul 2009
Nov 3rd, 2009
0
Re: JSP Page Interaction
First of all request.setAttribute is void. It doesn't return a value to put it in a string.

Secondly:

Quote ...
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:


JSP Syntax (Toggle Plain Text)
  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.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,260 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: how to increase users in tomcat-users.xml file automatically not manually
Next Thread in JSP Forum Timeline: hi~need some help~





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC