?
Solved

Compare variables in JSP

Posted on 2003-12-03
7
Medium Priority
?
463 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
Industry Leaders: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

New style of hardware planning for Microsoft Exchange server.
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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