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

📄 savesubscription.gv

📁 struts框架的script版本. 用于学习strust框架
💻 GV
字号:
import java.lang.reflect.InvocationTargetException;import org.apache.commons.beanutils.PropertyUtils;import org.apache.struts.webapp.example.*;import javax.servlet.http.HttpServletResponse;import javax.servlet.ServletException;form = struts.form;act = form.getAction();if (act == null) {    act = "?";}if (log.isDebugEnabled()) {    log.debug("SaveSubscriptionAction:  Processing " + act +              " act");}// Is there a currently logged on user?user = session.getAttribute(Constants.USER_KEY);if (user == null) {    if (log.isWarnEnabled()) {        log.warn(" User is not logged on in session "                  + session.getId());    }    struts.setForwardName("logon");    return;}if (struts.action.isCancelled(request)) {    if (log.isWarnEnabled()) {        log.warn(" Transact '" + act +                  "' was cancelled");    }    session.removeAttribute(Constants.SUBSCRIPTION_KEY);    struts.setForwardName("success");    return;}// Is there a related Subscription object?subscription = session.getAttribute(Constants.SUBSCRIPTION_KEY);if ("Create".equals(act)) {    subscription =        user.createSubscription(request.getParameter("host"));}if (subscription == null) {    if (log.isWarnEnabled()) {        log.warn(" Missing subscription for user '" +                  user.getUsername() + "'");    }    log.warn("bad request sent");    response.sendError(HttpServletResponse.SC_BAD_REQUEST,                       response.getMessage("error.noSubscription"));}// Was this transact a Delete?if (act.equals("Delete")) {    if (log.isTraceEnabled()) {        log.trace(" Deleting mail server '" +                  subscription.getHost() + "' for user '" +                  user.getUsername() + "'");    }    user.removeSubscription(subscription);    session.removeAttribute(Constants.SUBSCRIPTION_KEY);    try {        database = application.getAttribute(Constants.DATABASE_KEY);        database.save();    } catch (Exception e) {        log.error("Database save", e);    }    struts.setForwardName("success");    return;}// All required validations were done by the form itself// Update the persistent subscription informationif (log.isTraceEnabled()) {    log.trace(" Populating database from form bean");}try {    PropertyUtils.copyProperties(subscription, form);} catch (InvocationTargetException e) {    Throwable t = e.getTargetException();    if (t == null)        t = e;    log.error("Subscription.populate", t);    throw new ServletException("Subscription.populate", t);} catch (Throwable t) {    log.error("Subscription.populate", t);    throw new ServletException("Subscription.populate", t);}try {    database = application.getAttribute(Constants.DATABASE_KEY);    database.save();} catch (Exception e) {    log.error("Database save", e);}// Remove the obsolete form bean and current subscriptionif (struts.mapping.attribute != null) {    if ("request".equals(struts.mapping.scope))        request.removeAttribute(struts.mapping.attribute);    else        session.removeAttribute(struts.mapping.attribute);}session.removeAttribute(Constants.SUBSCRIPTION_KEY);// 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 + -