-1
我已經給了一個項目來開發一個登錄頁面,檢查用戶是否存在postgres數據庫,並允許他登錄,否則要求他作爲新用戶登錄,我已經進入if子句也但它不工作....我的代碼是 -檢票登錄頁面與數據庫連接
enter code here
package in.login;
import java.sql.Connection;
public class Page3 extends WebPage{
public Page3(){
final TextField uname = new TextField("uname", new Model());
final TextField password = new PasswordTextField("password", new Model());
add(new FeedbackPanel("feedback"));
Form form = new Form("f"){
protected void onSubmit() {
String v1= uname.getDefaultModelObjectAsString();
String v2 = password.getDefaultModelObjectAsString();
System.out.println(uname.getDefaultModelObjectAsString());
System.out.println(password.getDefaultModelObjectAsString());
try {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost/registration:5432",
"postgres",
"ashneel");
try {
conn.setAutoCommit(false);
PreparedStatement st = (PreparedStatement) conn.prepareStatement("select * from registration where uname='"+v1+"' and password='"+v2+"' ");
try{
if(password.equals(v2)) {
System.out.print("aaaaa");
setResponsePage(Inbox.class);
}
else {
System.out.print("new user");
}
setResponsePage(Inbox.class);
} finally {
st.close();
}
} catch (Exception e) {
conn.rollback();
throw e;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
form.add(uname);
password.add(StringValidator.minimumLength(5));
password.add(StringValidator.maximumLength(10));
form.add(password);
add(form);
form.add(new Link("link") {
public void onClick() {
Registr registr = new Registr();
setResponsePage(registr);
}
});
}
}
什麼的一部分是不工作?你有堆棧跟蹤嗎?它會編譯? – Makoto 2012-08-03 13:01:41
你使用'wicket-auth-roles'嗎?你的'Application'類是否擴展'AuthenticatedWebApplication'? – tetsuo 2012-08-04 13:49:51