-1

我正在尝试打开一个新窗口并在 struts 2 的过程中调用一个动作。

问题是jsp打开了,但是直到我按下刷新或从新的jsp开始,才会调用动作。

我希望执行该操作,然后重定向到相应的 jsp,但现在它重定向到与第一个映射结果对应的 jsp。

来自 javascript 的动作调用:

function displayGraph(graphName)
        {   alert("displayGraph");
            var url = 'drawCMGraph?data=' + encodeURIComponent(graphName);
            alert(url);
            window.open(url, "_blank",
            "directories=no, status=no,width=550, height=200,top=0,left=0");
        }

struts.xml 中的动作映射

<action name="drawCMGraph" class="com.casealerts.action.HomeAction" method="Drawgraph">
<result name="success">/casealerts/test.jsp</result>
<result name="error">/casealerts/Error.jsp</result>
        </action>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>Comp</display-name>
    <filter>  
        <filter-name>struts2</filter-name>  
     <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>  <!--This listener handles caching of data when the server context is loaded.-->
        <listener-class>CompListener</listener-class>
    </listener>
    <welcome-file-list>
        <welcome-file>/casealerts/Login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

行动

package com.casealerts.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.casealerts.businessdelegate.HomePageCMDelegate;
import com.casealerts.formbean.HomeForm;



public class HomeAction extends ActionSupport implements ModelDriven<HomeForm>,Preparable,ServletRequestAware
{

    /**
     * 
     */
    private static final long serialVersionUID = 272240572969090988L;
    Logger log=new Log4jHelper().getLogger(getClass());
    HomeDelegate hpd=null;
    private HttpServletRequest request;
    HomeForm form=null;
    private HttpSession session=null;

    @Override
    public void setServletRequest(HttpServletRequest request) {
        // TODO Auto-generated method stub
        this.request=request;

    }

    @Override
    public void prepare() throws Exception {
        // TODO Auto-generated method stub
        form=new HomeForm();

    }

    @Override
    public HomeForm getModel() {
        // TODO Auto-generated method stub
        return form;
    }

    public String Drawgraph()
    {
        session=request.getSession(true);
        hpd=new HomeDelegate(form,session);

        String result=hpd.getGraphData("alert", 1);

        return result;
    }
}
4

2 回答 2

0
var url = 'drawCMGraph?data=' + encodeURIComponent(graphName);
            alert(url);

尝试将其更改为

var url = 'drawCMGraph.action?data=' + encodeURIComponent(graphName);
            alert(url);
于 2013-04-18T12:03:40.180 回答
0

我找到了解决问题的方法。看来我们需要为动作类的 URL 中发送的数据创建一个变量以及 getter 和 setter。这适用于 IE,但它不适用于 Eclipse 浏览器

于 2013-04-20T07:41:42.790 回答