File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes else loop not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "else loop not working" Watch "else loop not working" New topic
Author

else loop not working

anu rani
Greenhorn

Joined: Aug 29, 2006
Posts: 14
i have a program whatever i write the code in else loop it is not working.
String s = request.getParameter("username");
String pass=request.getParameter("password");
out.println("username"+"<br>"+s);
out.println("pass"+"<br>"+pass);
String pwd=null;
Statement st=null;
ResultSet rs=null;
Connection con=null;
ConnectionBean1 cb = new ConnectionBean1();
con = cb.getConnection();

String str="select password,status from login where username='"+ s +"' and password='"+pass+"' ";
out.println(str);
st =con.createStatement();
rs=st.executeQuery(str);

while (rs.next())
{
stat=rs.getString("status");
pwd=rs.getString("password");

}
out.println("stat"+stat);

out.println("pass"+pass);
out.println("pwd"+pwd);

rs.close();
st.close();
con.close();
if(pwd.equals(pass))
{
out.println("successfull login");
response.sendRedirect("../mobile4/view.jsp");
}
else
{
out.println("please try again");
response.sendRedirect("../mobile4/err.jsp");
}


}
catch(Exception exception)
{



out.println(exception.toString());
}
%>
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

suppose, you give wrong username and password,then exception will occured here
right?

then you put yoour else block code into the Catch block.

Hope This Helps
baalu sasidhar
Greenhorn

Joined: Jun 25, 2008
Posts: 4
ARE U GETTING ANY EXCEPTIONS? IF YES CHECK WHAT EXCEPTION ARE U GETTING? LET ME KNOW WHETHER YOUR IF BLOCK IS WORKING?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Baalu, for all our eyes' sake, please KeepItDown. It looks like you're shouting at us.


Ping & DNS - my free Android networking tools app
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

And BTW else is not a loop.
Please UseAMeaningfulSubjectLine.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: else loop not working