Solved

Compare variables in JSP

Posted on 2003-12-03
7
458 Views
Last Modified: 2010-04-01
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;
  }
%>
0
Comment
Question by:894359
  • 3
  • 3
7 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 350 total points
ID: 9871663
try:

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

--or--

String selState2 = selState.equals("Other") ? txtStateOther : selSate;
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9871667
sorry, missing a ')' in the if statement above.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 9871812
just an additional info, if want to compare string without caps, can try:

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

cheers
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:894359
ID: 9872688
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
 

Author Comment

by:894359
ID: 9872703
tYPO... selSate instead of selState :)
0
 

Author Comment

by:894359
ID: 9872705
tYPO... selSate instead of selState :)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9875312
>> tYPO... selSate instead of selState :)
sorry, that was my fault.

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
getting param value 7 51
Is possible to make a jsp script work with oracle wallet? 7 101
how to exclude a file using regex 5 118
How can I   ajax html table  rows? 20 75
Troubleshooting common task sequence error codes
Learn how the use of a bunch of disparate tools requiring a lot of manual attention led to a series of unfortunate backup events for one company.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now