0

Struts Code:

action name="alreadylogin" class="struts.alreadylogin"

            result name="success">/indexlogin.jsp</result>
            <result name="error">/failure.jsp</result>
            <result name="input">/login.jsp</result>            
        </action>

Java Class Code:

public String loginemail;

    String loginpassword;

    public String execute()  {


try {
            Class.forName("oracle.jdbc.driver.OracleDriver");

            Connection con = DriverManager
                    .getConnection("jdbc:oracle:thin:system/hr@localhost:1521:XE");

            Statement st = con.createStatement();

            ResultSet rs = st.executeQuery("select * from  logininfo");

            while (rs.next()) {
                String lemail = rs.getString(3);
                String lpassword = rs.getString(4);



            if(lemail.equals(loginemail)&&(lpassword.equals(loginpassword)))

                return "success";

            }
}

            catch(SQLException s)
            {
                return "error";
            }
            catch(ClassNotFoundException c)
            {
                return "error";
            }

It shows the error to Insert Finally into the code or return a String. If I use finally, the return statement will execute no matter what which destroys the purpose of checking for a user to log in.

Roman C
  • 49,761
  • 33
  • 66
  • 176

2 Answers2

0

If this test is not passed, no result String is returned.

if(lemail.equals(loginemail)&&(lpassword.equals(loginpassword)))
    return "success";
}

Simply add

  else {
    return "input";
}

BTW you should never query for *, nor performing queries from the action itself.

And most even important, instead of querying ALL the fields of ALL the records from the database, traversing them in JAVA, try using the WHERE keyword :|

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

The finally block executed before return statement which any block should return in your case. The error is that you should return a string from the method execute regardless of implementation is used. If you are using try/catch blocks and if you place return in both blocks then you don't need a finally block to return a value from a method nor the return statement at the end of the method. Because if you try to place a return statement there you should get Unreachable code error, and there's no such error if you forgot to return from the code above.

Roman C
  • 49,761
  • 33
  • 66
  • 176