您需要使用Ajax 调用。请看下面的例子,
Struts.xml 配置:
<action name="**ActionName**" class="**Actionclass**" method="**Method-calling**">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
<result name="input">/Error.jsp</result>
</action>
</package>
动作类
public class ActionClass扩展 ActionSupport { private InputStream inputStream;
public String **Method-calling()**
{
//Calling Business Logic
if(Business logic check condition)
{
inputStream=new StringBufferInputStream("return x");
}
else
{
inputStream=new StringBufferInputStream("return y");
}
return SUCCESS;
}
public InputStream getInputStream()
{
return inputStream;
}
public String execute()
{
return SUCCESS;
}
}
Html 文件 Ajax 调用示例
jQuery('***#replace-with-tag-id***').on('***blur(can be any action)***', function() {
var varE = jQuery('***#replace-with-tag-id***').val();
jQuery.ajax({
method:"GET",
url: "***Actoin-name-struts.xml***.action", //"callAJax.action",
data: "email="+varEmail,
success: function(data)
{
if(""+data == "return x")
{
alert("x has been returned");
}
else
{
alert("y has been returned");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('Error=' + textStatus);
alert("errorThrown"+errorThrown);
alert("response text = "+XMLHttpRequest.responseText);
}
});
}
}).trigger('blur');
我希望,我已经消除了你的疑问。