码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-04-20 16:59:04      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

  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

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

标签:

原文地址:http://blog.csdn.net/tragedyxd/article/details/45151245

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!