• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Why don't you check it ?
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :-)
 
Onion rings are vegetable donuts. Taste this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic