Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compare variables in JSP

Posted on 2003-12-03
7
Medium Priority
?
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 1400 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 53

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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