@AndreaLigios, please explain the 2nd type of result, i.e. JSP-snippet.I don’t know how to use the JSP snippet as an ajax response.
Main.jsp (full)
<%@ taglib prefix="s" uri="struts-tags.tld" %>
<html>
<head>
<script>
$(function(){
$('#loader').on("keypress click", function(e) {
$.ajax({
url: "<s:url action='ajaxAction'/>",
}).done(function(result) {
$("#target").html(result);
});
});
});
</script>
</head>
<body>
<input type="button" id="loader" />
<div id="target"></div>
<body>
</html>
Struts.xml (relevant)
<action name="ajaxAction" class="foo.bar.AjaxAction">
<result>Snippet.jsp</result>
</action>
AjaxAction (relevant)
private String testString;
public String execute(){
testString = "I'm loaded with AJAX";
return SUCCESS;
}
Snippet.jsp (full)
<%@ taglib prefix="s" uri="struts-tags.tld" %>
TestString: <s:property value="testString" />
Output:
<body>
<input type="button" id="loader" />
<div id="target">TestString: I'm loaded with AJAX</div>
<body>
source
share