Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<jsp:forward ...> not acting the way it should.

 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m just practicing and came across this about jsp:forward. I wrote few beans (employee.java, person.java)...Those are fine.

In Index file (index.jsp) , request.getParameter("empID") is null here as I hoped it would be.
index.jsp



After clicking submit button, it goes to chosing.jsp.

In index.jsp, if I do not enter any data in the forms, then I hoped that I will get null for empID. However I do not.
I even tried using different empID values such as 111 and checked empID. But it is not working.

In short, it is not forwarding as I hoped it would.

In chosing.jsp






ok here welcome.jsp




Why does it not come here when I do not put any inputs or use 111 for empID? Another.jsp



 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to check for an empty string ?

if (request.getParameter("empID") == "111")

You must have forgotten how to compare String variables (SCJP).
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Did you try to check for an empty string ?

if (request.getParameter("empID") == "111")

You must have forgotten how to compare String variables (SCJP).


Is it going to be empty string or null string or " "?

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it going to be empty string or null string or " "?

Why don't you check it ?
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:
Is it going to be empty string or null string or " "?

Why don't you check it ?




Thank you for the hints. I spent a whole evening until midnight on this . grrr...

Yeep I have forgotten about Strings JAVA I think. How could I in such short time? blah

ANyway, I fixed it. thanks. I should have used the equals method as what I wanted is too check to make sure that two string vales are same not the two exact string objects..
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I am getting string with "" for not inputing any data in the form. Is that an empty string or string with no whitespace. I mean string with no contents and whitespace is empty right?

I assumed that I would get null string. The assumption was wrong

Secondly, I forgot about == and .equals
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assumed that I would get null string. The assumption was wrong

I always forget about it too.

Secondly, I forgot about == and .equals

You'll never forget it again now
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:
I assumed that I would get null string. The assumption was wrong

I always forget about it too.

Secondly, I forgot about == and .equals

You'll never forget it again now


Thanks. But how do I check to make sure that the user has atleast inputed a value ? The value can be anything other than whitespace. How Do I do this?

request.getParameter("empID").equals (" ") only checks for one whitespace. I want to make sure that doesnt matter how many whitespaces the user puts, I still check to make sure there is something else other than whitespace?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getParameter("empID") == null || "".equals(request.getParameter("empID").trim())

If you'd use EL instead of scriptlets, you could use the empty operator instead, with JSTL's c:if tag.
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:request.getParameter("empID") == null || "".equals(request.getParameter("empID").trim())

If you'd use EL instead of scriptlets, you could use the empty operator instead, with JSTL's c:if tag.


Thanks...

I am just learning the JSTL :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic