Compare variables in JSP

I want to compare a iquery variable to a string and re-assign it if neccessary. How do I do it?
///////////////////////////
Code sample
///////////////////////////
<% String selState = request.getParameter("selState"); %>
<% String txtStateOther = request.getParameter("txtStateOther"); %>

<%
  if( selState.equals("Other")
  {
    String selState2  = txtStateOther;
  }else{
      String selState2  = selState;
  }
%>
894359Asked:
Who is Participating?
 
kennethxuConnect With a Mentor Commented:
try:

String selState2 = selSate;
if( selState.equals("Other") selState2  = txtStateOther;

--or--

String selState2 = selState.equals("Other") ? txtStateOther : selSate;
0
 
kennethxuCommented:
sorry, missing a ')' in the if statement above.
0
 
Ryan ChongCommented:
just an additional info, if want to compare string without caps, can try:

String selState2 = selState.equalsIgnoreCase("Other") ? txtStateOther : selSate;

cheers
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
894359Author Commented:
I must be doing something wrong? It doesn't compile??? If I remove the last line below it will compile????

<% String selState = request.getParameter("selState"); %>
<% String txtStateOther = request.getParameter("txtStateOther"); %>

<% String selState2 = selState.equalsIgnoreCase("Other") ? txtStateOther : selSate; %>
0
 
894359Author Commented:
tYPO... selSate instead of selState :)
0
 
894359Author Commented:
tYPO... selSate instead of selState :)
0
 
kennethxuCommented:
>> tYPO... selSate instead of selState :)
sorry, that was my fault.

Glad to know your problem is resolved and thanks for the A grade.
0
All Courses

From novice to tech pro — start learning today.