struts-config.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources/>
<form-beans>
<form-bean type="tdy218.Register.Regactonform" name="Regactonform"/>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/add" scope="request" type="tdy218.Register.Regaction" name="Regactonform">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
</action-mappings>
</struts-config>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources/>
<form-beans>
<form-bean type="tdy218.Register.Regactonform" name="Regactonform"/>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/add" scope="request" type="tdy218.Register.Regaction" name="Regactonform">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
</action-mappings>
</struts-config>
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources/>
<form-beans>
<form-bean type="tdy218.Register.Regactionform" name="Regactionform"/>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/add" scope="request" type="tdy218.Register.Regaction" name="Regactionform">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
</action-mappings>
</struts-config>Regaction.java
package tdy218.Register;
import java.sql.*;
import javax.servlet.http.*;
import tdy218.Register.DatabaseConnection;
import org.apache.struts.action.*;public class Regaction extends Action
{
public ActionForward register(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
{
Regactionform login = (Regactionform)form;
String target = "failure";
PreparedStatement ps = null;
String sql = "insert into register(username,password) values(?,?)";
try{
ps = new DatabaseConnection().getConnection().prepareStatement(sql);
ps.setString(1,login.getUsername());
ps.setString(2,login.getPassword());
ps.execute();
if((ps.getMoreResults()==false)&&(ps.getUpdateCount()==-1))
{
target="success";
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
ps.close();
new DatabaseConnection().getConnection().close();
}
return mapping.findForward(target);
}
}
HttpServletRequest request, HttpServletResponse response)