Link to home
Start Free TrialLog in
Avatar of princehyderabad
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("product"))
                                {
                                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("product"). 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("product")=HELLO
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of princehyderabad
princehyderabad

ASKER

Okay equals works, but it is still going to else part.

if (rs.getString(2).equals(request.getParameter("product")))

                                {
                                  System.out.println("Print IF Part");
                                 response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                                        String newLocn = "errorUpload.jsp";
                                        response.setHeader("Location",newLocn);
                                }

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?
My else part has this code:
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                                        String newLocn = "view_current_releases.jsp";
                                        response.setHeader("Location",newLocn);

And I see my page is directed to view_current_releases.jsp
can you post the comnplete if/else statement
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.