Solved

JSP Empty String Problem

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

617 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