Javascript 从外部web门户将参数传递给GWT nocache.js
我创建了一个根容器ID为“widgetcainer”的Javascript 从外部web门户将参数传递给GWT nocache.js,javascript,gwt,methods,native,Javascript,Gwt,Methods,Native,我创建了一个根容器ID为“widgetcainer”的GWT小部件,相应的编译文件是gwtwidget.nocache.js。我已经创建了这个小部件的war文件,并托管在本地服务器localhost:8888/gwtwidget中 我创建了另一个jsp应用程序,index.jsp如下:(将GWT模块集成到jsp应用程序中) 但无法在GWT小部件中获取参数值。有谁能帮我解决这个问题吗 提前感谢。如果您想使用查询字符串传递参数,那么它不是直接的。有办法做到这一点。你可以参考以下帖子: 还有一种方
GWT
小部件,相应的编译文件是gwtwidget.nocache.js。我已经创建了这个小部件的war文件,并托管在本地服务器localhost:8888/gwtwidget中
我创建了另一个jsp应用程序,index.jsp如下:(将GWT
模块集成到jsp
应用程序中)
但无法在GWT
小部件中获取参数值。有谁能帮我解决这个问题吗
提前感谢。如果您想使用查询字符串传递参数,那么它不是直接的。有办法做到这一点。你可以参考以下帖子: 还有一种方法,我觉得更简单。您可以在jsp文件中设置cookie。您可以在GWT模块中读取cookie
<html>
<head>
<script type="text/javascript">
document.cookie="appId=461333815262909"
</script>
<script type="text/javascript" language="javascript" src="http://localhost:8888/gwtwidget/gwtwidget/gwtwidget.nocache.js"></script>
</head>
<body>
<div id="widgetContainer"></div>
</body>
</html>
public static native String getParameter( String moduleName, String parameterName ) /*-{
var search = "/" + moduleName + ".nocache.js";
var scripts = $doc.getElementsByTagName( "script" );
for( var i = 0; i < scripts.length; ++i ) {
if( scripts[ i ].src != null && scripts[ i ].src.indexOf( search ) != -1 ) {
var parameters = scripts[ i ].src.match(/\w+=\w+/g);
for( var j = 0; j < parameters.length; ++j ) {
var keyvalue = parameters[ j ].split( "=" );
if( keyvalue.length == 2 && keyvalue[ 0 ] == parameterName ) {
return unescape( keyvalue[ 1 ] );
}
}
}
}
return null;
}-*/;
<html>
<head>
<script type="text/javascript">
document.cookie="appId=461333815262909"
</script>
<script type="text/javascript" language="javascript" src="http://localhost:8888/gwtwidget/gwtwidget/gwtwidget.nocache.js"></script>
</head>
<body>
<div id="widgetContainer"></div>
</body>
</html>
String param = Cookies.getCookie("appId");