Struts2 逐步成长(六):Ajax配置

  1. result字符串处理:inputStream = new ByteArrayInputStream("your string".getBytes("UTF-8")); 
  2. 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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。