princehyderabad
asked on
If condition problem
hi,
Why is my If condition not getting executed properly. Anything wrong in code.
while(rs.next())
{
if ( rs.getString(2)== request.getParameter("prod uct"))
{
System.out.println("CAME DOSN");
}
else
{ System.out.println("ELSE part"); }
}
Even though value of rs.getString(2) is equal to value of request.getParameter("prod uct"). IF part is not getting excuted. Only else part been excuted.
I tried to see on console by having system.out.print.... Both values are identical.
rs.getString(2) =HELLO
request.getParameter("prod uct")=HELL O
Why is my If condition not getting executed properly. Anything wrong in code.
while(rs.next())
{
if ( rs.getString(2)== request.getParameter("prod
{
System.out.println("CAME DOSN");
}
else
{ System.out.println("ELSE part"); }
}
Even though value of rs.getString(2) is equal to value of request.getParameter("prod
I tried to see on console by having system.out.print.... Both values are identical.
rs.getString(2) =HELLO
request.getParameter("prod
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if the rs can return null then you should check for that also
== tests if the are the same object, equals() tests if the value of two objects is equal.
ASKER
Okay equals works, but it is still going to else part.
if (rs.getString(2).equals(re quest.getP arameter(" product")) )
{
System.out.println("Print IF Part");
response.setStatus(HttpSer vletRespon se.SC_MOVE D_PERMANEN TLY);
String newLocn = "errorUpload.jsp";
response.setHeader("Locati on",newLoc n);
}
as per my code it should redirect to errorUpload.jsp correct ? then why is it also following else part ...
if (rs.getString(2).equals(re
{
System.out.println("Print IF Part");
response.setStatus(HttpSer
String newLocn = "errorUpload.jsp";
response.setHeader("Locati
}
as per my code it should redirect to errorUpload.jsp correct ? then why is it also following else part ...
what make u think it is executing the else block?
ASKER
My else part has this code:
response.setStatus(HttpSer vletRespon se.SC_MOVE D_PERMANEN TLY);
String newLocn = "view_current_releases.jsp ";
response.setHeader("Locati on",newLoc n);
And I see my page is directed to view_current_releases.jsp
response.setStatus(HttpSer
String newLocn = "view_current_releases.jsp
response.setHeader("Locati
And I see my page is directed to view_current_releases.jsp
can you post the comnplete if/else statement
ASKER
On I Used <jsp:forward page="errorUpload.jsp" /> instead of my above code to redirect and it worked. Thanks for your time.
Meanwhile OBject do u hv to me to look: https://www.experts-exchange.com/questions/21396244/Arrange-my-Servlet-code.html
Code is working only need proper arragement of code here and there. I hv seen in past you were great help to me. Thanks.
Meanwhile OBject do u hv to me to look: https://www.experts-exchange.com/questions/21396244/Arrange-my-Servlet-code.html
Code is working only need proper arragement of code here and there. I hv seen in past you were great help to me. Thanks.