Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Struts 1.2中使用mapping.findForward进行转发_Javascript_Struts 1 - Fatal编程技术网

Javascript 在Struts 1.2中使用mapping.findForward进行转发

Javascript 在Struts 1.2中使用mapping.findForward进行转发,javascript,struts-1,Javascript,Struts 1,在Struts config.xml中,添加了以下内容: public class MyAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception { String status="success

Struts config.xml
中,添加了以下内容:

public class MyAction extends Action
{   
    public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {

        String status="success";
        HttpSession session = request.getSession(true);
        System.out.println("My Action---setting key value");
        request.getSession().setAttribute("key1","check");

        //response.sendRedirect("http://localhost:9080/FamiliarPortal/jsp/inicio.jsp");
        return mapping.findForward(status); 

    }
}
<action path="/myAction" type="iusa.ubicacel.actions.MyAction" validate="false" >
         <forward name="success" path="/jsp/inicio.jsp"/>       
</action>
<servlet>
        <servlet-name>GetFAP</servlet-name>
        <servlet-class>iusa.ubicacel.actions.map.GetFAP</servlet-class>
    </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
<servlet-mapping>
        <servlet-name>GetFAP</servlet-name>
        <url-pattern>/GetFAP</url-pattern>
</servlet-mapping>
inicio.jsp
中,添加了以下内容:

public class MyAction extends Action
{   
    public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {

        String status="success";
        HttpSession session = request.getSession(true);
        System.out.println("My Action---setting key value");
        request.getSession().setAttribute("key1","check");

        //response.sendRedirect("http://localhost:9080/FamiliarPortal/jsp/inicio.jsp");
        return mapping.findForward(status); 

    }
}
<action path="/myAction" type="iusa.ubicacel.actions.MyAction" validate="false" >
         <forward name="success" path="/jsp/inicio.jsp"/>       
</action>
<servlet>
        <servlet-name>GetFAP</servlet-name>
        <servlet-class>iusa.ubicacel.actions.map.GetFAP</servlet-class>
    </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
<servlet-mapping>
        <servlet-name>GetFAP</servlet-name>
        <url-pattern>/GetFAP</url-pattern>
</servlet-mapping>
上面的代码在使用
mapping.findForward
时没有调用GetFAP servlet。但是当我使用
response.sendRedirect(“整个jsp路径”)
时,它正在调用servlet


有人能告诉我我做错了什么吗?

您使用的是相对URL而不是绝对URL

当您直接呈现JSP时,
./GetFAP
映射起作用,因为您必须从
/JSP
目录向上移动一个级别。1

当您从一个动作呈现JSP时,您正在从动作的路径向上移动一个级别,也就是说,URL中不再有可向上移动的
/JSP
目录

这是使用相对路径可能是个坏主意的众多原因之一



1 JSP文件应位于
WEB-INF
目录中,以避免客户端直接访问。

您显示的转发与“GetFAP”无关,我不知道您为什么会这样认为。转发在struts-config.xml.Onload of incio.JSP calls requestXML()中映射到inicio.JSP函数调用GetFAPThen问题可能是您使用了相对URL,但很难说。你知道,你可以使用浏览器的调试工具来调试它。是的。当我将它改为“var url=”GetFAP?requestURL=“+reqURL;”时,它起了作用。但我真的不明白为什么。当我没有使用Struts时,同样的事情也起了作用。原因是什么?还有“/GetFAP”和“./GetFAP”之间的区别是什么?