1

I am getting gra value from one.jsp as follows

<script language="javascript">
function gotoAddPanelAction(elem)
{ 
var st=elem.value;
if(st!="")
{
Popup=window.open('SelectInterviewPannel2.jsp?gra='+st,'Popup','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes',400,400);
}
else
{
validateForm(document.frm);
}
}
</script>

I am retriving the value in SelectInterviewPannel2.jsp as follows

<td width="60%" class="txt-lable">
 <Select name="grade" ><option value="" selected>Select</option>
 <%
String gra = request.getParameter("gra");
 if(gra.value=="Level 1") {
%>
<option value="E1">E1</option><option value="E2">E2</option><option value="E3">E3</option><option value="E4">E4</option></select>
<% } else  {%>
 <option value="M1">M1</option><option value="M2">M2</option></select>
<% } %>
 </td>

My problem is in SelectInterviewPannel2.jsp if statement is not executing . I am getting only drop down box for select with no values in it.

Akshatha
  • 599
  • 2
  • 10
  • 26

3 Answers3

5
 if(gra.value=="Level 1") {

Shouldn't you use equals() method for string comparission

Some Suggestions:

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • @Akshatha Can't you see this[NULL handling] thing taken care in [this](http://stackoverflow.com/questions/5699249/how-to-pass-value-from-one-jsp-to-other-through-window-open/5699276#comment-6512459) comment of mine – jmj Apr 18 '11 at 12:48
4

First of all why this title: how to remove comma in integer in java it does not match with your question.

As an answer:

Instead of this

if(gra.value=="Level 1") 

use this

if(gra.equals("Level 1")) 

In java == Compares references, not values and to compare values of string you should use .equals(str).

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • well I recommend you to go for JSTL , but still if you want to continue with this java code in jsp then `String gra = request.getParameter("gra"); if("Level 1".equals(gra)) {` should work – jmj Apr 18 '11 at 06:41
3

If gra parameters does not exist , request.getParameter("gra") will return null and comparing using if(gra.equals("Level 1")) will throw out Null pointer exception . So you can try to use if("Level1".equals(gra)) to avoid the Null pointer exception when the gra parameters does not exist

Ken Chan
  • 84,777
  • 26
  • 143
  • 172