1

我有一个 struts 方法,在我添加验证之前它工作正常,但是一旦我添加了验证方法,我调用的方法就不会被调用,它也没有显示异常。

struts-config.xml

<action path="/RolesAction"  name="SecurEyesForm" type="com.secureyes.eswastha.struts.web.action.RolesAction" scope="request" parameter="method" validate="true" input="/WEB-INF/Masters/RolesMaster.jsp">
  <forward name="rolesHome" path="/WEB-INF/Masters/RolesMaster.jsp"></forward>        
</action>

动作类:

package com.secureyes.eswastha.struts.web.action;

import com.secureyes.eswastha.struts.web.dao.RolesDAO;
import com.secureyes.eswastha.struts.web.viewmodel.RolesViewModel;
import com.secureyes.eswastha.struts.web.viewmodel.UserViewModel;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;

public class RolesAction extends SecureyesAction {

    private String forwardRequestTo = "authentication-failed";

    public ActionForward goToHome(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        DynaValidatorForm formObj = (DynaValidatorForm) form;
        int resourceid = 0;
        String pageToken = "";
        boolean isValidMenuRequest = false;
        UserViewModel userVM = new UserViewModel();

        if (request.getSession(false).getAttribute("userDetails") != null) {
            userVM = (UserViewModel) request.getSession(false).getAttribute("userDetails");
        }
        if (formObj.get("pagetoken") != null) {
            pageToken = formObj.get("pagetoken").toString();
        }

        if (formObj.get("resourceid") != null) {
            resourceid = Integer.parseInt(formObj.get("resourceid").toString());
        }

        boolean isValidPageToken = isValidPageToken(userVM.getPagetoken(), pageToken);
        if (isValidPageToken) {
            isValidMenuRequest = isValidMenuRequest(resourceid, userVM.getUserRoleid());
            if (isValidMenuRequest) {
                forwardRequestTo = "rolesHome";
            }
        }
        disableAutocompleteFeature(response);
        return mapping.findForward(forwardRequestTo);
    }

    public ActionForward saveRolesDetails(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.out.println("save roles");

        DynaValidatorForm formObj = (DynaValidatorForm) form;
        String rolename = "", description = "", functionType = "", roleid = "", saveOrupdateStatus = "", pageToken = "";
        int loggedinuserid = 0;
        UserViewModel userVM = new UserViewModel();
        RolesViewModel dvm = new RolesViewModel();
        RolesDAO rolesDAO = new RolesDAO();

        if (formObj.get("rolename") != null) {
            rolename = formObj.get("rolename").toString();
        }

        if (formObj.get("description") != null) {
            description = formObj.get("description").toString();
        }

        if (formObj.get("functionType") != null) {
            functionType = formObj.get("functionType").toString();
        }

        if (formObj.get("roleid") != null) {
            roleid = formObj.get("roleid").toString();
        }

        if (formObj.get("pagetoken") != null) {
            pageToken = formObj.get("pagetoken").toString();
        }

        if (request.getSession(false).getAttribute("userDetails") != null) {
            userVM = (UserViewModel) request.getSession(false).getAttribute("userDetails");
        }

        loggedinuserid = userVM.getUserid();

        boolean isValidPageToken = isValidPageToken(userVM.getPagetoken(), pageToken);
        if (isValidPageToken) {
            if (functionType.equals("add")) {
                dvm.setRolename(rolename);
                dvm.setDescription(description);
                dvm.setUserid(loggedinuserid);
                saveOrupdateStatus = rolesDAO.saveRolesDetails(dvm, functionType);
            } else if (functionType.equals("edit")) {
                dvm.setRoleid(Integer.parseInt(roleid));
                dvm.setRolename(rolename);
                dvm.setDescription(description);
                dvm.setUserid(loggedinuserid);
                saveOrupdateStatus = rolesDAO.saveRolesDetails(dvm, functionType);
            }
            request.setAttribute("message", saveOrupdateStatus);
            forwardRequestTo = "rolesHome";
        }
        return mapping.findForward(forwardRequestTo);
    }

    public ActionForward deleteRoles(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DynaValidatorForm formObj = (DynaValidatorForm) form;
        String saveOrupdateStatus = "", pageToken = "", roleid = "";
        RolesDAO rolesDAO = new RolesDAO();
        UserViewModel userVM = new UserViewModel();

        if (formObj.get("roleid") != null) {
            roleid = formObj.get("roleid").toString();
        }

        if (formObj.get("pagetoken") != null) {
            pageToken = formObj.get("pagetoken").toString();
        }

        if (request.getSession(false).getAttribute("userDetails") != null) {
            userVM = (UserViewModel) request.getSession(false).getAttribute("userDetails");
        }

        boolean isValidPageToken = isValidPageToken(userVM.getPagetoken(), pageToken);
        if (isValidPageToken) {
            saveOrupdateStatus = rolesDAO.deleteRoles(Integer.parseInt(roleid));
            request.setAttribute("message", saveOrupdateStatus);
            forwardRequestTo = "rolesHome";
        }
        return mapping.findForward(forwardRequestTo);
    }

    public List getAutocompleteRolesData(String rolesName) {
        List rolesNameList = new ArrayList<String>();
        RolesDAO rolesDAO = new RolesDAO();
        try {
            rolesNameList = rolesDAO.getAutocompleteRolesData(rolesName);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return rolesNameList;
    }

    public List getRolesDescriptionAutocompleteData(String rolesDescription) {
        List rolesNameList = new ArrayList<String>();
        RolesDAO rolesDAO = new RolesDAO();
        try {
            rolesNameList = rolesDAO.getRolesDescriptionAutocompleteData(rolesDescription);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return rolesNameList;
    }

    private String constructRolesSearchQuery(String rolename, String description) {
        StringBuilder rolesSearchQuery = new StringBuilder();
        rolesSearchQuery.append("select roles.rolename,roles.description,roles.roleid from m_roles as roles ");
        if (!rolename.equals("")) {
            rolesSearchQuery.append(" where roles.rolename='").append(rolename).append("' ");
        }
        if (!description.equals("")) {
            if (!rolename.equals("")) {
                rolesSearchQuery.append(" and roles.description='").append(description).append("'");
            } else {
                rolesSearchQuery.append(" where roles.description='").append(description).append("'");
            }
        }
        return rolesSearchQuery.toString();
    }

    public Map getRolesResultHTML(String rolename, String description,HttpServletRequest request) {
        Map roleHTMLMap = new LinkedHashMap();
        String roleQuery = "";
        String path=request.getContextPath();
        roleQuery = constructRolesSearchQuery(rolename, description);
        RolesDAO rolesDAO = new RolesDAO();
        roleHTMLMap = rolesDAO.getRolesResultHTML(roleQuery,path);
        return roleHTMLMap;
    }

    public boolean isRolesExist(String rolename) {
        boolean isRolename = false;
        RolesDAO rolesDAO = new RolesDAO();
        isRolename = rolesDAO.isRolesExist(rolename);
        return isRolename;
    }

    public Map getRoles() {
        Map map = new LinkedHashMap();
        RolesDAO dao = new RolesDAO();
        map = dao.getRoles();
        return map;
    }
}

这就是我调用该方法的方式:

function dataSave() {
                alert("data Save");
                getBlanket('continueDIV');
                document.forms[0].action="RolesAction.htm";
                document.forms[0].method.value="saveRolesDetails";
                document.forms[0].submit();   
            }
4

0 回答 0