Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JSP Empty String Problem

Posted on 2002-04-08
3
Medium Priority
?
272 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 300 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

971 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