0
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="registerform" type="com.register.actions.DynaActionForm">
<form-property name="emailid" type=""></form-property>
<form-property name="password" type=""></form-property>
<form-property name="cpassword" type=""></form-property>
<form-property name="firstname" type=""></form-property>
<form-property name="lastname" type=""></form-property>
<form-property name="gender" type=""></form-property>
<form-property name="submitError" type=""></form-property>
</form-bean>
</form-beans>
<action-mappings>
<action path="/doRegister" type="com.register.actions.UserRegistrationAction"
name="registerform" scope="request" validate="true" input="input">
<forward name="input" path="/index.jsp" />
<forward name="success" path="/welcome.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
</action-mappings>
<controller inputForward="true" />
<message-resources parameter="com.register.util.ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/org/apache/struts/validator/validator-rules.xml,
/WEB-INF/validation.xml" />
<set-property property="stopOnFirstError" value="true" />
</plug-in>
</struts-config>
這是我的DynaAction形式如何使用execute方法
package com.register.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import com.register.util.ConnectionUtils;
import com.register.util.DbUtils;
public class UserRegistration extends User{
private static final long serialVersionUID = 1L;
public boolean newuserregistration() throws Exception
{
PreparedStatement psUserRegistration = null;
String sqlUserRegistration = null;
boolean isRegistered = false;
Connection conn = ConnectionUtils.getConnection();
sqlUserRegistration = "insert into user_master(sEmail, sPassword, sFirstName," +
" sLastName, cGender, iUserType, sCreatedDate, cStatus)" +
" values(?,md5(?),?,?,?,1,sysdate(),'A')";
try{
psUserRegistration = conn.prepareStatement(sqlUserRegistration);
psUserRegistration.setString(1, this.getEmail());
psUserRegistration.setString(2, this.getPassword());
psUserRegistration.setString(3, this.getFirstName());
psUserRegistration.setString(4, this.getLastName());
psUserRegistration.setString(5, this.getGender());
psUserRegistration.executeUpdate();
isRegistered=true;
}
catch(Exception e)
{
String errorMessage=e.getMessage();
e.printStackTrace();
if(errorMessage.indexOf("Duplicate entry")>=0)
{
this.setDbError("error");
}
isRegistered=false;
e.printStackTrace();
}
DbUtils.close(psUserRegistration, conn);
return isRegistered;
}
}
This is database connection class for all .
package com.register.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import com.register.model.UserRegistration;
public class UserRegistrationAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
boolean action_perform = false;
String action_target;
UserRegistration u = new UserRegistration();
ActionMessages errors_mesg = new ActionMessages();
//UserRegisterForm uf = (UserRegisterForm) form;
DynaActionForm uf=(DynaActionForm) form;
return null;
}
}
這是Action類註冊到數據庫用戶信息:我想用戶詳細信息註冊到數據庫,請告訴我,我怎麼會寫代碼用於向數據庫註冊用戶細節。登記工作finewith ActionForm的,但我要創建使用DynaActionForm的,請幫助我,我的新嘗試學習Struts框架