Struts2.3接收post方式提交的表单参数的方式
生活随笔
收集整理的這篇文章主要介紹了
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>();}@Resourcepublic 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;}@Overridepublic 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>();}@Resourcepublic 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;}}總結
以上是生活随笔為你收集整理的Struts2.3接收post方式提交的表单参数的方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java游戏有易筋经_易筋经- Java
- 下一篇: 盐城大数据产业园人才公寓_岳西大数据产业