⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saveregistration.gv

📁 struts框架的script版本. 用于学习strust框架
💻 GV
字号:
import java.lang.reflect.InvocationTargetException;import org.apache.commons.beanutils.PropertyUtils;import org.apache.struts.action.*;import org.apache.struts.webapp.example.*;import javax.servlet.ServletException;form = struts.getForm();String act = form.getAction();if (act == null) {    act = "Create";}database = application.getAttribute(Constants.DATABASE_KEY);if (log.isDebugEnabled()) {    log.debug("SaveRegistrationAction:  Processing " + act +              " act");}// Is there a currently logged on user (unless creating)?user = session.getAttribute(Constants.USER_KEY);if (!"Create".equals(act) && (user == null)) {    if (log.isTraceEnabled()) {        log.trace(" User is not logged on in session "                  + session.getId());    }    struts.setForwardName("logon");    return;}// Was this transact cancelled?if (struts.action.isCancelled(request)) {    if (log.isTraceEnabled()) {        log.trace(" Transact '" + act +                  "' was cancelled");    }    session.removeAttribute(Constants.SUBSCRIPTION_KEY);    struts.setForwardName("success");    return;}// Validate the transactal control tokenerrors = new ActionErrors();if (log.isTraceEnabled()) {    log.trace(" Checking transactal control token");}if (!struts.action.isTokenValid(request)) {    errors.add(ActionErrors.GLOBAL_ERROR,               new ActionError("error.transact.token"));}struts.action.resetToken(request);// Validate the request parameters specified by the userif (log.isTraceEnabled()) {    log.trace(" Performing extra validations");}value = form.getUsername();if (("Create".equals(act)) &&        (database.findUser(value) != null)) {        errors.add("username",                   new ActionError("error.username.unique",                                   form.getUsername()));}if ("Create".equals(act)) {    value = form.password;    if ((value == null) || (value.length() <1)) {        errors.add("password",                   new ActionError("error.password.required"));    }    value = form.password2;    if ((value == null) || (value.length() < 1)) {        errors.add("password2",                   new ActionError("error.password2.required"));    }}// Report any errors we have discovered back to the original formif (!errors.isEmpty()) {    struts.action.saveErrors(request, errors);    struts.action.saveToken(request);    struts.setForward(struts.mapping.getInputForward());    return;}    // Update the user's persistent profile informationtry {    if ("Create".equals(act)) {        user = database.createUser(form.username);    }    oldPassword = user.password;    PropertyUtils.copyProperties(user, form);    if ((form.password == null) ||        (form.password.length() < 1)) {        user.setPassword(oldPassword);    }} catch (InvocationTargetException e) {    Throwable t = e.getTargetException();    if (t == null) {        t = e;    }    log.error("Registration.populate", t);    throw new RuntimeException("Registration.populate", t);} catch (Throwable t) {    log.error("Registration.populate", t);    throw new RuntimeException("Subscription.populate", t);}try {    database.save();} catch (Exception e) {    log.error("Database save", e);}// Log the user in if appropriateif ("Create".equals(act)) {    session.setAttribute(Constants.USER_KEY, user);    if (log.isTraceEnabled()) {        log.trace(" User '" + user.getUsername() +                  "' logged on in session " + session.getId());    }}// Remove the obsolete form beanif (struts.mapping.getAttribute() != null) {    if ("request".equals(struts.mapping.scope))        request.removeAttribute(struts.mapping.attribute);    else        session.removeAttribute(struts.mapping.attribute);}// Forward control to the specified success URIif (log.isTraceEnabled()) {    log.trace(" Forwarding to success page");}struts.setForwardName("success");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -