I have this problem: I need to get some simple data from Action and send back to JSP (already loaded), so I have to manage the action to recover that data with jQuery $.ajax method. So here is my code:
MyAction.java
private String employee;
private InputStream inputStreamEmployee;
//these with getter/setter
public String someData() throws Exception{
employee= "John Doe";
inputStreamEmployee = new ByteArrayInputStream(
employee.getBytes(StandardCharsets.UTF_8));
return "SUCCESS";
}
struts.xml
<action name="getSomeData" method="someData" class="MyAction">
<result name="success" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStreamEmployee</param>
</result>
</action>
data.js
function getData(){
$.ajax({
type: 'GET',
url: 'getSomeData',
dataType: 'text',
async: true,
success: function (data) {
alert(data);
},
error: function (data) {
alert('no data!!');
}
});
I checked this resource, but I need the javascript part. So I debugged and checked the development. The javascript method calls the action in java, and action returns success, but the data in function(data) doesn't get the InputStream correctly, it just get the whole html webpage source, as shown in the image:

What am I doing wrong? Thanks in advance.