- result字符串处理:inputStream = new ByteArrayInputStream("your string".getBytes("UTF-8"));
- xml针对上面return的配置
action:
package web; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; import entity.Deposit; import service.DepositService; //file:///D:/iProgram/JAVA/toolsJar/struts2/struts-2.3.20/docs/docs/ajax.html public class DepositAction extends AbstractAction<Deposit, DepositService> { InputStream inputStream; public String transaction() throws UnsupportedEncodingException { inputStream = new ByteArrayInputStream(service.transaction().toString() .getBytes("UTF-8")); return SUCCESS; } @Override public String getAll() { // TODO Auto-generated method stub return null; } @Override public String save() { return null; } @Override public void prepareSave() { // TODO Auto-generated method stub } @Override public String delete() { // TODO Auto-generated method stub return null; } @Override public String findById() { // TODO Auto-generated method stub return null; } @Override public String update() { // TODO Auto-generated method stub return null; } @Override public void prepareUpdate() { // TODO Auto-generated method stub } public InputStream getInputStream() { return inputStream; } public void setInputStream(InputStream inputStream) { this.inputStream = inputStream; } }
xml:
<action name="deposit-*" class="DepositAction" method="{1}"> <result type="stream"> <param name="contentType">text/html</param> <param name="inputName">inputStream</param> </result> </action>
需要注意的的地方:
<param name="inputName">inputStream</param>
这里的inputStream 和 action中的变量名要相同,并且提供getter
时间: 2024-11-12 18:07:48