Solved

JSP Empty String Problem

Posted on 2002-04-08
3
260 Views
Last Modified: 2006-11-17
hi,

I have two edits on my first jsp page, which values I send via form submit to the second page.

I want to test on my second page whether these values is empty, and if they are, forward to another page.

The problem is that when the values are empty, the jsp engine regards them as "not empty"?? and doesnt go into the fowarding
if statement.

I have even tested the values by displaying them in the second page, but no luck.

If I go and set these values to "" before i execute the if, it works!

I must be missing something obvious.

--page 1--

<input type="text" name="edtItemNumber">
 <input type="text" name="edtStoreLocation">


--page 2--

String item = request.getParameter("edtItemNumber");
String location = request.getParameter("edtStoreLocation");

if ((item == "") || (location == ""))
{application.getRequestDispatcher("/oraerror.jsp?ErrorStr=Please complete Item number and Store Location." ).forward(request,response);}


Please help.
0
Comment
Question by:barnarp
[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
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 75 total points
ID: 6927302
You shouldn't use == to test String equality. It tests for object equality, not whether the two objects represent the same string. To test if a string is empty use one of the following:

item.equals("")

or

item.length()==0

0
 

Author Comment

by:barnarp
ID: 6927313
Thanks alot.

Do you know of any reference on the net, where I can learn more about string functions etc ?

Pierre
0
 
LVL 92

Expert Comment

by:objects
ID: 6927338
Pierre,

Try:
http://java.sun.com/docs/books/tutorial/java/data/strings.html

And of course the good old javadoc :-)

http://www.objects.com.au
Brainbench MVP for Java 1
http://www.brainbench.com
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

728 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