Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameter passing problem  RSS feed

 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My problem is that I want to pass a parameter from a.jsp to b.jsp. I want to store my variable in e hidden input, and when I submit a link, the a.jsp will send the parameter to b.jsp.

a.jsp
==============================================
<form action="gekozenKind.jsp" method="post" name="submitKind">
<a href="gekozenKind.jsp">
<%= v_naam.get(i) %></a>
<br>
<%= v_gebDatum.get(i) %>
<br>
<%= v_afkomst.get(i) %>
<input type="hidden" name="weesID" value="<%= v_id.get(i) %>">
</form>

b.jsp
==============================================
<%= request.getParameter("weesID") %>

I tried this code but the <%= request.getParameter("weesID") %> returns always a null.

Could someone help me to fix this prob?

Abu Romaysa,
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not submitting the form.
Either replace the link with a submit button.
<input type="submit".....

or use the onclick event in the anchor tag to submit the form instead of excecuting the link.
 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not want to use a button, because then I'll get a page with more then 21 buttons. I tried it with the button and it works great, but don't know how to do that with a link cuse that's what I wanna do.

Thanks
Abu Romaysa
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36463
462
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Azz,
You can also pass the parameter in the link itself. Note that it will be a GET request rather than a POST request:


If you realy need a post, you can intercept the user's click through javascript. Have the onClick handler call a user defined function which submits the form.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you're repeating this in a loop, you'll want to build the form's id attribute dynamically. The "return false" statement in the onclick event keeps it from actually behaving like a link (probably redundent in this case but it makes for clearer code.).

I know this works in Mozilla/Firefox and MSIE 6 and up. You'll have to test on legacy (pre DOM) browsers if you plan on supporting them.

I had to mispell onklick to get this top post in this forum. Change the 'k' to a 'c' to get it working.
[ December 26, 2004: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!