Skip to Main Content

Pass value and Validate

User_OMEF8Feb 15 2013 — edited Feb 17 2013
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
This post has been answered by r035198x on Feb 17 2013
Jump to Answer
Comments
Post Details
Added on Feb 15 2013
1 comment
1,211 views