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:
- Struts 2 encapsulates form data into list and map sets
- Serverlet: How to Add, Delete, Modify and Query item code
- Destructor abnormal stuck bug
- The difference between sleep() and wait() in Java
- Two ways of fuzzy query in mybatis
- non-static variable this cannot be referenced from a static context
- Basic use of filter
- Java compareto() method
- Java – read all the files and folders in a certain directory and three methods to get the file name from the file path
- [Solved] Access /oauth/token in SpringCloud OAuth2 and report server_error
- Simple use of namedparameterjdbctemplate of spring
- Java gets the type t.class of generic t
- Java – how to shuffle an ArrayList
- Conversion between list and string array
- entity framework core + SQLite Error 1: ‘no such table: Blogs’.
- Login authority verification
- Implementation of multithread sequential alternate execution by using lock in Java
- LDAP: error code 32 – No Such Object
- Java uses the same event listener for the same type of component
- Using global timing task cronutil in hutool tool class