Struts2.3接收post方式提交的表单参数的方式

一:方式一:通过request来获取,首先让action实现ServletRequestAware接口,然后通过request来获取提交的参数,代码如下:

package cn.gov.csrc.flight.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.gov.csrc.base.action.BaseAction;
import cn.gov.csrc.cms.model.UserInfo;
import cn.gov.csrc.cms.service.UserService;
import cn.gov.csrc.flight.model.Flgtinfo_D;
import cn.gov.csrc.flight.service.FlgtinfodService;

@Controller
@ParentPackage("json-default") 
@Scope("prototype")
public class FlgtinfodAction extends BaseAction<Flgtinfo_D> implements ServletRequestAware{
	
	private static final long serialVersionUID = 1L;
	
	private FlgtinfodService flgtinfodService;
	
	private Map<String, Object> dataMap;
	
	HttpServletRequest request;
	
	public FlgtinfodAction(){
		dataMap = new HashMap<String, Object>();
	}
	
	@Resource
	public void setFlgtinfodService(FlgtinfodService flgtinfodService) {
		this.flgtinfodService = flgtinfodService;
	}
	
	@Action(value = "FlgtinfodAction_detail", results = { @Result(name = "success", type = "json", params = {"root", "dataMap" }) })
	public String detail(){
		dataMap.clear(); 
		//查询出港详情(根据用户id,列表到详情的唯一编号)
		String id = this.request.getParameter("id");
		Flgtinfo_D flgtinfo_D = flgtinfodService.getEntity(id);
		String airline2 = flgtinfo_D.getAirline();
		// 出港详情放入到dataMap中
		dataMap.put("flgtinfo_D", flgtinfo_D);
		// 放入一个是否操作成功的标识 
		dataMap.put("success", true);
		return "success";
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}
	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
}

二:方式二,直接在action里面写你要提交的参数,然后提供set,get方法,代码如下:

package cn.gov.csrc.flight.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.gov.csrc.base.action.BaseAction;
import cn.gov.csrc.cms.model.UserInfo;
import cn.gov.csrc.cms.service.UserService;
import cn.gov.csrc.flight.model.Flgtinfo_D;
import cn.gov.csrc.flight.service.FlgtinfodService;

@Controller
@ParentPackage("json-default") 
@Scope("prototype")
public class FlgtinfodAction extends BaseAction<Flgtinfo_D>{
	
	private static final long serialVersionUID = 1L;
	
	private Integer id; // 列表到详情的唯一标识
	
	private FlgtinfodService flgtinfodService;
	
	private Map<String, Object> dataMap;
	
	public FlgtinfodAction(){
		dataMap = new HashMap<String, Object>();
	}
	
	@Resource
	public void setFlgtinfodService(FlgtinfodService flgtinfodService) {
		this.flgtinfodService = flgtinfodService;
	}
	
	@Action(value = "FlgtinfodAction_find", results = { @Result(name = "success", type = "json", params = {"root", "dataMap" }) })
	public String find() {
        dataMap.clear(); 
		//查询出港信息
		List<Flgtinfo_D> list = flgtinfodService.findAllFlgtinFods();
		// 出港信息放入到dataMap中
		dataMap.put("list", list);
		// 放入一个是否操作成功的标识 
		dataMap.put("success", true);
		return "success";
	}
	
	@Action(value = "FlgtinfodAction_detail", results = { @Result(name = "success", type = "json", params = {"root", "dataMap" }) })
	public String detail(){
		dataMap.clear(); 
		//查询出港详情(根据用户id,列表到详情的唯一编号)
		id = model.getId();
		Flgtinfo_D flgtinfo_D = flgtinfodService.getEntity(id);
		String airline2 = flgtinfo_D.getAirline();
		// 出港详情放入到dataMap中
    		dataMap.put("flgtinfo_D", flgtinfo_D);
    		// 放入一个是否操作成功的标识 
    		dataMap.put("success", true);
		return "success";
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}
	
	
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

迷彩的博客

你的鼓励将是我最大的创作动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值