Solved

JSP Empty String Problem

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 39
Running JavaFX on JDeveloper 12C 1 77
mysql jsp example issue 32 73
Java class and jar 3 42
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

733 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