1. Use ActionContext class
//1获取ActionContext对象
ActionContext context = ActionContext.getContext();
//2.调用方法获取key-value值
Map<String, Object> map = context.getParameters();
Set<String> set = map.keySet();
for(String key :set){
Object[] o = (Object[]) map.get(key);
System.out.println(Arrays.toString(o));
}
. Use ServletActionContext
//使用ServletActionContext对象获取request对象
HttpServletRequest request = ServletActionContext.getRequest();
//2.使用request对象获取表单数据
String username = request.getParameter("username");
String password = request.getParameter("password");
String address = request.getParameter("address");
System.out.println("username="+username);
System.out.println("password"+password);
System.out.println("address"+address);
3. Implement ServletRequestAware interface
public class FormDemo3Action extends ActionSupport implements ServletRequestAware {
HttpServletRequest httpServletRequest;
@Override
public void setServletRequest(HttpServletRequest httpServletRequest) {
this.httpServletRequest=httpServletRequest;
}
@Override
public String execute(){
String username = httpServletRequest.getParameter("username");
String password = httpServletRequest.getParameter("password");
System.out.println("username="+username);
System.out.println("password="+password);
return NONE;
}
}
div>
Read More:
- Django + jQuery get data in the form + Ajax send data
- Four ways to get Django parameters in request
- Struts 2 encapsulates form data into list and map sets
- No data: data: get host by name failed in TCP_ Connect() error resolution
- @Solution to get / set error in eclipse after using data annotation
- Web Crawler: How to get the data in the web page and disguise the header, disguise as a browser to visit many times, avoid a single visit leading to IP blocked
- Two ways of fuzzy query in mybatis
- IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
- Error in idea @ data entity class get / set
- About content type ‘multipart / form data…’ not support
- [idea] error occurred when using @ data annotation in Lombok: no related get / set method was found
- One of the ways to solve the problem of internal server error in flash learning
- How to batch create folders in Excel form and copy the specified files to a new folder
- How to Fix Sklearn ValueError: This solver needs samples of at least 2 classes in the data, but the data
- Java get try, catch error information data
- Several ways to view spark task log
- mysql load data infile ERROR 13 (HY000): Can’t get stat of
- spring boot-beans in application context form a cycle
- Several ways to check the IP address of raspberry pie
- Solution to page scroll bar failure caused by opening secondary spring frame in Ant Design modal form