File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Passing Values..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing Values....." Watch "Passing Values....." New topic

Passing Values.....

Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
My knowledge of JSP will be apparent here so there should be a easy answer. I have tried many different ways to do what I am asking:
How do I select a option value and within the next <FORM> check for that value and run statements depending on that value.
If option = "xxx"
--Do this
Thanks in advance!
yi zhu
Ranch Hand

Joined: Sep 10, 2002
Posts: 41
Try javascript!
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
I didn't get in alot of detail with my initial problem and I appreciate the response.
I have two Form tags and on the Click event on the first form I trigger a Javascript funtion which in turn submits the form which I want to populate second form with data from the selected data depending on what was selected (If statements embedded in the second Form tag).
My problem right now is that when the first form is submitted and I have the parameter in the URL, my jsp calls does not return anything:
--Second form
String arg = request.getParameter("cmbFactor");

if (arg == "LAE_MONTHLY_EXPENSE") {
My URL has this displayed:
I've also tried it as:
if (<%request.getParameter("cmbFactor");%> == "LAE_MONTHLY_EXPENSE") --and this also does not return anything
Any ideas?
Dinesh Kumar
Ranch Hand

Joined: Jul 03, 2002
Posts: 54
Can you try if (arg.equals("LAE_MONTHLY_EXPENSE"))
This should evaluate to true.
You can't expect the == to return true as it behaves differently. Details are a bit long to go into here.
[ December 07, 2002: Message edited by: Dinesh Kumar ]
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
Having tried the following suggestion, I get the below error:
if (arg.equals("LAE_MONTHLY_EXPENSE")) {
Internal Servlet Error:
at org.apache.jasper.runtime.PageContextImpl.handlePageException(
Root cause:
at jsp._0002fjsp_0002fFactors_0002ejspFactors_jsp_83._jspService(
Everything that the I have researched points to the fact that what I am doing should work. I'm sure that I'm missing a simple element that is not screaming at me to add....
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Looks like the value for "cmbFactor" is not available so you get NullPointerException when you try to reference "arg".
So you can take necessary measure(s) to avoid this. Simplest I can think of is switch the position i.e. if("someString".equals(arg)) ...)
and do some client side validation for to check if values are selected.
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
I seem to be back where I started. What I want to accomplish is:
Select a option value from one <form> and pass that value to the second <form> to be evaluated to display data depending on what was selected in the first form.
The first <form> on a Onclick method that runs some JAVASCRIPT that stores the value in a varable, then submits the first <form>:
function frmFactorSelect_submit(i) {
if (i == 1) {
SelectedFactor = document.frmMaintFactor.cmbFactor.value;
In the second <form> I am checking for the value "SelectedFactor":
if (SelectedFactor) == "LAE_MONTHLY_EXPENSE")
for (int i=0;i<factorLMEList.getNumberOfFactorLME();i++)
nextfactor = factorLMEList.getFactorLMEs(i);
startdate = nextfactor.getstartDate();
enddate = nextfactor.getendDate();
orgunit = nextfactor.getorgUnit();
out.print("<OPTION selected value='" + 1 + "'>" + startdate + ", " + enddate + ", " + orgunit + "</OPTION>");
out.print ("<OPTION value='0'>It don't work</OPTION>");
This is not working.
This can't be that of a difficult problem, but I have been working on it for a week and no solution as of yet.
Thanks in advance.
Bhupinder Dhillon
Ranch Hand

Joined: Oct 12, 2000
Posts: 124
Originally posted by Wayne Burr:
[QB]if (SelectedFactor) == "LAE_MONTHLY_EXPENSE")

try this...
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
the last suggestion:
if (new String("LAE_MONTHLY_EXPENSE").equalsIgnoreCase(request.getParameter("SelectedFactor"))){
Worked like a charm! Don't understand why the other solutions did not work, but progress has been made
Thanks to All!
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Wayne, you have learned JSP but forgotten Java itself...

This is almost always NOT what you want.

The above is almost always what you do want. The first example checks to see if the object 'arg' is equal to the object "LAE_MONTHLY_EXPENSE" this may or may not be true depending on how the value got into arg.
Also, the equalsIgnoreCase() is good as is trim() to use but should not be necessary as you should be using a define (static final String) somewhere.
Meidi Novel

Joined: Dec 13, 2002
Posts: 2
try this example :
<form name="f">
<select name="testselect" onChange="window.location='test.jsp?val='+document.f.testselect.value">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>

String val= "";
if(request.getParameter("testselect") != null)
val = request.getParameter("testselect");
// check for null before assigning values..good practice.. )

<form name="f2">
<input type="text" value="<%=val%>">
//the value of val will be printed in the text box of the second form

i hope this will solve ur problem
I agree. Here's the link:
subject: Passing Values.....
jQuery in Action, 3rd edition