• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in if test

 
Abhra Kar
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one home.html which takes only a name and directly transfered to need.jsp
need.jsp--

<%@ page isELIgnored="false" %>
<html><body bgcolor="#124560">
<h2>Welcome to our page</h2>
<% if (request.getParameter("userName")== null){%>
<jsp:forward page="HandleIt.jsp" />
<%}%>
Hello ${param.userName}
</body></html

HandleIt.jsp--
<html><body>
sorry you need to log in again
<form action="need.jsp">
name is :<input type="text" name="userName"><br>
<input type="submit" value="click it">
</form>
</body></html>

problem is when we give value to userName in home.html then it will prints fine but when we ive no value that means null then also the request is not going to HandleIt.jsp which means if test is not been checked .

I can't found what is the problem.

If anyone want the total web application I have made then please give me the email id i will send it .
I want the solution very much.
 
Rodrigo Vieira
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that username is null? maybe you are trying to give an empty value, like "". Try to put a system.out to see which value it has.
[ July 18, 2008: Message edited by: Rodrigo Villelaaa ]
 
Abhra Kar
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No sir I haven't put any " " value

even if I use <% if (request.getParameter("userName")=="Abhra"){%>

and pass any other name in home.html then also the othername value will print
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% if (request.getParameter("userName")== null or ''){%>


This will work fine for you, sometimes the blank values are treated as '' not null. Add this condtion, it wil work for you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Amandeep Jaaaaaaa", please check your private messages for an important administrative matter.
 
Abhra Kar
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply but it will not works even if we write
<% if (request.getParameter("userName")=="Amandeep"){%> instead of
<% if (request.getParameter("userName")==null){%> and give some some other value like "Abhra" at home.html then also Abhra is printed it will not forward the page .
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use the EL 'empty' operator to check the posted value?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic