大哥大姐帮帮忙咯,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配置)
<!--新增加的模块!功能是登陆进去根据登录用户的session取出用户的相应信息 --> <action path="/newtask" scope="request" validate="false" type="com.coreram.framework.common.action.NewTask" parameter="method" > <forward name="ok" path="/success.jsp"/> </action>
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; }}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");} }<global-exceptions> <exception key="general.exception" type="java.lang.Exception" scope="request" handler="com.coreram.framework.exception.RedirectExceptionHandler" path="/error.jsp" /> </global-exceptions>
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; }}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'Test.jsp' starting page</title> </head> <body> <form action="TestAction.do" method="get"> <input type="text" maxlength="12" name="userno"> <input type="submit" value="OK!"> </form> </body></html>
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.apache.struts.actions.DispatchAction;import com.coreram.framework.manager.sysuser.SysUser;import com.coreram.framework.util.Pub;public class TestAction extends DispatchAction { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try { String userno = Pub.val(request, "userno"); if (userno.equals("tom")) { return mapping.findForward("success"); } //SysUser user = (SysUser)request.getSession().getAttribute("cur_user"); //System.out.println(user.getUsername()); //System.out.println(user.getUserno()); //SysUser user = (SysUser) request.getSession().getAttribute(com.coreram.framework.Globals.USER_KEY); } catch (Exception e) { } return mapping.findForward("failed"); }}求高人指点啊!!