大哥大姐帮帮忙咯,js调用struts1无论怎么找不到action ?求解

   阅读
大哥大姐帮帮忙咯,js调用struts1无论如何找不到action ?求解!
公司以前的一个项目,开发是用struts1开发的,现在要增加一个新的模块,根据登录进去的用户的session取出username,根据用户的身份来得到一张待办事件的表,我的思路是在登录加载页面的时候,利用js调用一个函数,直接onload过去,传过去的是一个action请求,没有任何参数,因为在登录的时候,LoginAction已进行request.getSession().setAttribute(Globals.USER_KEY, su);操作了,我在我的action中直接取出su.getusername在进行操作即可, 这个是我的思路,现在的问题上我还没有进入action,在我自己的action类上面加了断点,压根就没进去,求各位高手帮帮忙,小弟谢过了。

一下为代码:struts-congig.xml;(由于不需要表单验证,没有form-bean配置)
XML code
        <!--新增加的模块!功能是登陆进去根据登录用户的session取出用户的相应信息  -->
        <action    path="/newtask" scope="request"  validate="false" 
         type="com.coreram.framework.common.action.NewTask" parameter="method" >
        
        <forward name="ok" path="/success.jsp"/>
        
        </action>



我自己的action类,只是为了测试,里面的代码基本可以无视:
Java code

package com.coreram.framework.common.action;

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.springframework.web.struts.DispatchActionSupport;

public class NewTask  extends DispatchActionSupport{

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

        if ("tom".equals("tom")) {
            return mapping.findForward("ok");
        }
        
        return null;
    }
}




javascript:
JScript code

function doNewsTask(){
    //task.jsp一开始加载首先调用这个函数,把action传过去,获取到当前session的username!!!    
    try {

        //alert("error");
       //location.href ="/Test.jsp";这种写法是正确的!!
      //window.location.href="/Test.jsp"; 这种写法是错误的!!     
    var url="/newtask.do";
    window.location.href=url;
    }
    catch(e)
    
    {alert("wrong");}
    

}



另外struts-congig.xml中的全局异常节点使用了一个异常处理类,因为程序不是我写的,我是新来的,所以我现在最怀疑这个类引发我所有的问题,因为如上的javascript路径应该是正确的,可是一登陆就会出现异常页面,我也一起贴出来

XML code

<global-exceptions>
        <exception key="general.exception" type="java.lang.Exception"
            scope="request" handler="com.coreram.framework.exception.RedirectExceptionHandler"
            path="/error.jsp" />
    </global-exceptions>



Java code

public class RedirectExceptionHandler
    extends ExceptionHandler {

  private static org.apache.log4j.Logger logger = org.apache.log4j.LogManager.getLogger("RedirectExceptionHandler");
  public ActionForward execute(Exception ex,
                               ExceptionConfig ae,
                               ActionMapping mapping,
                               ActionForm formInstance,
                               HttpServletRequest request,
                               HttpServletResponse response) throws
      ServletException {
    ActionForward forward = null;
    ActionError error = null;
    String property = null;
    if (ae.getPath() != null) {
       forward = new ActionForward(ae.getPath(),true);
     
    }
    else {
      forward = mapping.getInputForward();
    }

    // Figure out the error
    if (ex instanceof ModuleException) {
      error = ( (ModuleException) ex).getError();
      property = ( (ModuleException) ex).getProperty();
    }
    else {
      logger.error(ex.getMessage());
      error = new ActionError(ae.getKey(), ex.getMessage());
      property = error.getKey();
    }

    // Store the exception
    request.setAttribute(com.coreram.framework.Globals.KEY_ERROR_MESSAGE, ex.getMessage());
    storeException(request, property, error, forward, ae.getScope());
    return forward;
  }

}


阅读