File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes <jsp:forward ...> not acting the way it should. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<jsp:forward ...> not acting the way it should. " Watch "<jsp:forward ...> not acting the way it should. " New topic
Author

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

Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
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




Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Did you try to check for an empty string ?

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

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


[My Blog]
All roads lead to JavaRanch
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Why don't you check it ?
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
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

Joined: Nov 08, 2008
Posts: 72
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Nov 08, 2008
Posts: 72
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Nov 08, 2008
Posts: 72
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 :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <jsp:forward ...> not acting the way it should.
 
Similar Threads
Problem with the <c:out> that provides a default attribute
please solve this EL
param in jsp forward
When you are using EL, do we HAVE to explictly write servlet code?
Problem With jsp:forward