0

I am calling a javascript function from gwt client side using JSNI like follow:

anchor.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
               execute(notification.getActionCode(), notification.getParams());
            }
});

private static native String execute(String functionName, String params)/*-{
        try{
           $wnd[functionName](params);
        }catch(e){
            alert(e.message);
        }
}-*/;

My problem is that my javascript function contains window.open("ServletName?...."). When clicking on the anchor, the window opened with error below: The requested resource (/es/gwt/core/ServletName) is not available.

if i replace window.open("ServletName?....") by window.open("../../ServletName?...."), the window open successfully, but these javascript functions are used also outside gwt so i cant modify it .

I dont know why the part /gwt/core is being added to the url which is causing the problem. Is there a way in gwt before executing the javascript function, to extract its content and adding the "../.." before the url? i mean heaving the javascript function name, can we get its content before calling the execute function? in my case my javascript function is a follow:

function everlinked_AddSpace(spaceId){
        window.open('ELUtilities?Service=Space&action=homePage&SpaceId='+spaceId+'&Template=apps/everlinked/templates/spaces/space_main.htm','_blank');;
    }

i need to modify it in gwt client side and call it with the new modifications.

I appreciate if someone could help me.

4

1 に答える 1

0

悪いアプローチを使用して問題を解決しようとしていると思います。

簡単な方法は、URL リライターを使用するurl-pattern、gwt アプリから送信された相対パスを同じサーブレットにルーティングするように web.xml を変更することです。

おそらく、web.xml に次のようなものがあります。

<servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>maynamespace.ServletName</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/ServletName</url-pattern>
</servlet-mapping>

したがって、このブロックを web.xml に追加できます。

<servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/es/gwt/core/ServletName</url-pattern>
</servlet-mapping>

url-pattern正規表現 (/path/* および *.ext) のセットが非常に限られていることに注意してください。この場合、フル パスを記述する必要があります。

于 2013-04-26T06:19:06.703 に答える