大家好,我是java struts的初学者,我正在创建简单的注册表单,但在提交表单后,null正在插入数据库表中。我已经创建了表单类名称作为RegistrationForm.java程序正在运行,但null正在插入我的操作代码是---
public class RegistrationAction extends Action {
private Connection con = null;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
RegistrationForm objReg = new RegistrationForm();
String userName = (String) objReg.getTxtusername();
String userPass = (String) objReg.getTxtpassword();
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///test", "root", "");
if (!con.isClosed()) {
PreparedStatement ps = (PreparedStatement) con.prepareStatement("INSERT >INTO tblUserdetails(fldUsername,fldPassword) VALUES (?,?) ");
ps.setString(1, userName);
ps.setString(2, userPass);
ps.execute();
} else {
errors.add("SQL", new ActionMessage("error.SQLConnectivity"));
}
return mapping.findForward(SUCCESS);
}
}
package com.vaannila.form;
import org.apache.struts.action.ActionForm;
public class RegistrationForm extends ActionForm {
private String txtusername;
private String txtpassword;
private String txtrepassword;
private String txtemail;
public String getTxtusername() {
return txtusername;
}
public void setTxtusername(String txtusername) {
this.txtusername = txtusername;
}
public String getTxtpassword() {
return txtpassword;
}
public void setTxtpassword(String txtpassword) {
this.txtpassword = txtpassword;
}
}