Solved

Compare variables in JSP

Posted on 2003-12-03
7
454 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 49

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Display the newly inserted values 3 72
jersey maven project error 7 134
dynamic reloading of jsp in jetty 2 114
withoutString  challenge 40 149
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

11 Experts available now in Live!

Get 1:1 Help Now