我的应用程序有一种昂贵的服务方法,其结果必须是1)检查错误; 2)通过URL(即与JavaScript变量相对)呈现给Java applet。方法结果是一个字符串,而applet只能 ,能够从文件或URL加载数据。
我尝试使用会话变量处理问题:
def action1 = {
def input = params['input']
def result = expensiveServiceMethod( input )
def failed = result == null
session['result'] = result
render( view:'view1', model:[failed:failed] )
}
def action2 = {
def result = session['result']
render( result )
}
然后,在view1
中,根据失败状态有条件地显示applet,applet通过action2
URL访问结果。
不幸的是,result
中的action2
即将出现null
。我已在result
中确认null
不 action1
。我做错了吗?
注意
我本来会使用flash
,但是为了初始化applet还有其他请求。
答案 0 :(得分:1)
小程序无法跟踪自己的会话cookie。因此,当您的applet向action2发送第二个请求时 - 它不会将会话cookie发送回服务器。因此,对于服务器而言,它就像一个全新的会话,在action1期间在会话中设置的任何内容都不会在action2中可用。您必须在applet中跟踪cookie并在拨打电话时将其发送回服务器。
我从未这样做过,但我认为您可以在客户端使用Apache commons http客户端(applet) - 它支持跟踪cookie
请参阅此question -