This discussion is archived
1 Reply Latest reply: Feb 17, 2013 12:03 AM by r035198x RSS

Pass value and Validate

976563 Newbie
Currently Being Moderated
Why will this NOT validate correctly in my IF Statement? Basically, a user chooses an option from the drop down list. The value is passed to t.jsp (itself) and if the option "All" is chosen, then it does something. If any of the years are chosen, then it does something else.

t.jsp (simplified version of what I want)

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<html>
<form method="get" action="t.jsp">
Select Year:
<select name="year">
<option value="All">All</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select><br>
<input type="submit" value="Submit">
</form>
</html>

<%
String selectedValue = request.getParameter("year");
String yearq = "";
//String temp = selectedValue;
int numb = 0;

out.println(selectedValue + " 1selectedValue");
out.println(yearq + " 1yearq");
out.println(numb + " 1numb");
//out.println(temp + " 1temp");

     if(selectedValue == "All")
     {
          yearq = "new statement '" + selectedValue + "' ";
          out.println("IF not ALL, then " + yearq);
     }
     else
     {
          selectedValue = "20%";
          yearq = "";
          out.println("IF ALL, Then Selected Value is: " + selectedValue);
     }

out.println(selectedValue + " 2selectedValue");
out.println(yearq + " 2yearq");
out.println(numb + " 2numb");
//out.println(temp + " 2temp");

//out.println("Line2, my selected value is: '" + temp + "' and then i have this value now. '" + yearq + "' <--- there!");

%>

Please help! Thanks.

Edited by: 973560 on Feb 15, 2013 1:13 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points