Solved

JSP Empty String Problem

Posted on 2002-04-08
3
212 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

760 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

20 Experts available now in Live!

Get 1:1 Help Now