你为什么不尝试用Ajax做到这一点?你可以执行一个动作,操纵数据,然后在JSP中得到结果?
在JSP:
function javascript_function(inputIfAny)
{
$.getJSON("<s:property value='%{ajaxCallUrl}' />",
{ value: value},
function(data)
{
dataAttributeValue = data.valueToSendToJSP; // If needed
});
}
<s:url id="ajaxCallUrl" action="actionName" method="ajaxMethod" />
而且在Struts 2的动作:
public void ajaxAccountUpdateHandle()
{
Map<String, Object> params = ActionContext.getContext().getParameters();
String value = params.get("numAcn");
try
{
JsonFactory f = new JsonFactory();
JsonGenerator generator = f.createJsonGenerator(response.getOutputStream());
// Do stuff
generator.writeStartObject();
generator.writeStringField("valueToSendToJSP", "foo");
generator.writeEndObject();
generator.flush();
generator.close();
}
catch (JsonGenerationException e)
{
}
catch (IOException e)
{
}
}
这样,你甚至不需要在struts XML的条目。
我试过了。它只是给了我一个空白页面。我试图使用GET和POST方法,以相同的结果 –
也,我试图读取变量的值使用 –
我已编辑我的答案签出。 – Babel