📄 joinaction.java
字号:
package dummies.struts.music;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
/**
* @author Mike Robinson
*
*/
public class JoinAction extends Action
{
/**
* Handles request from user
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
*/
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
Boolean bCancel = (Boolean)request.getAttribute("org.apache.struts.action.CANCEL");
if(bCancel != null)
if(bCancel.booleanValue())
return (mapping.findForward("cancel"));
// compare password with password2
if(((String)((DynaValidatorForm)form).get("password2")).equals((String)((DynaValidatorForm)form).get("password")))
{
// create a new JoinBean passing the datasource
JoinBean jb = new JoinBean(getDataSource(request, "musiccollection"));
// create an account for the user
UserDTO user = jb.createUser((String)((DynaValidatorForm)form).get("fname"),
(String)((DynaValidatorForm)form).get("lname"),
(String)((DynaValidatorForm)form).get("email"),
(String)((DynaValidatorForm)form).get("password"));
if(user != null)
{
// save UserDTO in session
request.getSession().setAttribute("user",user);
return (mapping.findForward("success"));
}
else // could not add the use. Must be because already exists.
{
// create ActionError and save in the request
ActionErrors errors = new ActionErrors();
ActionError error = new ActionError("error.join.exists");
errors.add("join",error);
saveErrors(request,errors);
return (mapping.findForward("failure"));
}
}
else // passwords did not match
{
// create ActionError and save in the request
ActionErrors errors = new ActionErrors();
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
ActionError error = new ActionError("error.join.passmismatch",
bundle.getString("join.password2"),
bundle.getString("join.password"));
errors.add("password2",error);
saveErrors(request,errors);
return (mapping.findForward("failure"));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -