• 创建 Controller


    创建 Controller

      LogonAction.java:

    package org.monotonous.struts;

    import java.util.Locale;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpSession;
    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.util.MessageResources;
    import org.apache.commons.beanutils.PropertyUtils;

    public final class LogonAction extends Action {
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception {
    Locale locale = getLocale(request);
    MessageResources messages = getResources(request);

    // Validate the request parameters specified by the user
    ActionErrors errors = new ActionErrors();
    String username =
    (String) PropertyUtils.getSimpleProperty(form, "username");
    String password =
    (String) PropertyUtils.getSimpleProperty(form, "password");

    if ((username != "foo") || (password != "bar"))
    errors.add(ActionErrors.GLOBAL_ERROR,
    new ActionError("error.password.mismatch"));

    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
    saveErrors(request, errors);
    return (mapping.getInputForward());
    }

    // Save our logged-in user in the session
    HttpSession session = request.getSession();
    // Do something with session...

    // Remove the obsolete form bean
    if (mapping.getAttribute() != null) {
    if ("request".equals(mapping.getScope()))
    request.removeAttribute(mapping.getAttribute());
    else
    session.removeAttribute(mapping.getAttribute());
    }

    // Forward control to the specified success URI
    return (mapping.findForward("success")); 
  • 相关阅读:
    同步内核缓冲区sync、fsync和fdatasync函数
    HDU 1496 Train Problem I 火车问题1(桟,水)
    HDU 1496 Equations 等式(二分+暴力,技巧)
    HDU 2577 How to Type (DP,经典)
    HDU 1247 Hat’s Words (字符串匹配,暴力)
    HDU 1548 A strange lift 奇怪的电梯(BFS,水)
    HDU 1711 Number Sequence (数字KMP,变形)
    204 Count Primes 计数质数
    203 Remove Linked List Elements 删除链表中的元素
    202 Happy Number 快乐数
  • 原文地址:https://www.cnblogs.com/encounter/p/2189250.html
Copyright © 2020-2023  润新知