AJAX调用struts动作不起作用

时间:2012-11-02 08:57:48

标签: javascript ajax struts

我有一个要求,我必须从struts动作类中检查一些内容,然后使用在JS fx中调用的ajax调用将结果发送回浏览器。问题是我无法点击动作类和控制台抛出以下错误: org.apache.struts.action.RequestProcessor processActionCreate无法创建路径/ ChangePwdAjax的操作实例                                  抛出java.lang.ClassNotFoundException:test.ChangePwdAjaxAction.java

编译类并且包上下文是有效的test.ChangePwdAjaxAction.java

任何想法我做错了什么和哪里?

这是我到目前为止所写的内容。

JS代码

function checkError()
{
var valuePassword="test";

var url = "/test/ChangePwdAjax.do?newPass="+valuePassword;
        var xmlHTTP = getXMLHTTPRequest();


        xmlHTTP.onreadystatechange = function() { 
        handleResponse(xmlHTTP); }

        xmlHTTP.open("GET",url,true);

        xmlHTTP.send();


}

function handleResponse(xmlHTTP){
    alert("handleResponse");
        if (xmlHTTP.readyState == 4 && xmlHTTP.status == 200) {
            alert("handleResponse");
            var xmlDoc = xmlHTTP.responseXML;

            alert(xmlDoc.documentElement.getElementsByTagName("pwdFlag")[0].text);

        }       
    }

function getXMLHTTPRequest(){
    alert("getXMLHTTPRequest");
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
        // IE
        else if (window.ActiveXObject) {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        else{
        alert("XMLHttpRequest is not supported!");
        }
    }

动作类代码

public class ChangePwdAjaxAction extends Action {


    public ActionForward execute(final ActionMapping mapping, final ActionForm form,
            final HttpServletRequest request,final HttpServletResponse response)

    {

        System.out.println("----IN--AJAX ACTION----------");
        final HttpSession session= request.getSession(false);

        if(session==null || session.getAttribute("user_id")==null){

            return mapping.findForward("sessionexpired");
        }


        final String user_id=(String)session.getAttribute("user_id");

        try{


            final BusinessDelegate busdel=new BusinessDelegate(user_id,session.getId());

            String newpwd = (String)request.getParameter("newPass");



            boolean b=busdel.checkOldPWd(user_id, newpwd);
            //checking return values from bus delegate
            response.setContentType("text/xml");
            PrintWriter printwriter = response.getWriter();

            printwriter.println("<?xml version=\"1.0\"?>");
            printwriter.println("<Root>");

            if(b)
            {
                System.err.println("----New password Failed--Y--------");   
            printwriter.println("<pwdFlag>"+"Y"+"</pwdFlag>");
            }
            else
            {
                System.out.println("----New password OK---N-------");   
                printwriter.println("<pwdFlag>"+"N"+"</pwdFlag>");
            }


            printwriter.println("</Root>");


            }catch(Exception e){
                logger.logCommon("Login Action : Login Process in Action : ", "EXCEPTION");
                logger.logError(e);

            }


        return null;
    }


}

Struts-config条目

<action path="/ChangePwdAjax" type="test.ChangePwdAjaxAction.java"/>

1 个答案:

答案 0 :(得分:0)

OOps这必须是

  

action path =“/ ChangePwdAjax”type =“test.ChangePwdAjaxAction”/&gt;

而不是

  

action path =“/ ChangePwdAjax”type =“test.ChangePwdAjaxAction.java”/&gt;