1. Encapsulate form data into Map collection
1. Create MapAction class
import cn.entity.User;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
public class MapAction extends ActionSupport {
private Map<String, User> map;
public Map<String, User> getMap() {
return map;
}
public void setMap(Map<String, User> map) {
this.map = map;
}
@Override
public String execute(){
System.out.println(map);
return NONE;
}
}
2. Create a map. The JSP p>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/map.action" method="post">
username:<input name="map[0].username" type="text"><br>
password:<input name="map[0].password" type="password"><br>
<br><br>
username:<input name="map[1].username" type="text"><br>
password:<input name="map[1].password" type="password"><br>
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
Add the following statement
to the struts.xml file
<struts>
<package name="myPackage" extends="struts-default" namespace="/">
<!-- <action name="data3" class="cn.data.DateDemo2Action"></action>-->
<!-- <action name="list" class="cn.data.ListAction"></action>-->
<action name="map" class="cn.data.MapAction"></action>
</package>
</struts>
** flow: ** browser in parsing the form data will find the getMap method in the MapAction entity class to get the Map class object, and then in the User entity class to find setUsername() and other set methods to encapsulate the data in the entity class object
To sum up: encapsulate the data List set contract Map the same
Read More:
- Under idea struts.xml The problem of “red” in extends = “struts default”
- Three ways to get form data in struct2
- Django + jQuery get data in the form + Ajax send data
- Under idea2020.3 struts.xml The solution of “red report” based on extensions = “struts default” in
- Common attributes and methods of list and map in Dar
- Data analysis to obtain Yahoo stock data: some problems are encountered when using panda datareader (cannot import name ‘is_ list_ Like ‘problem)
- About content type ‘multipart / form data…’ not support
- Error handling when ABP specifies map object during map operation
- Matplotlib of data visualization plt.xlim The () ylim() function sets the x-axis and y-axis range coordinates
- IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
- How many pieces of data can list store in Java?
- Struts2 is cracked, a serious loophole, a perfect solution
- In Struts2, the value read from the foreground JSP page is null
- Map to vector pair map.second sort
- Android 9 (P) recovery upgrade Map of ‘@/cache/recovery/block.map’ failed problem analysis guide
- Compare whether two sets are the same in Java
- @Value sets the default value
- Easynvr operation log reports an error. Fatal error: concurrent map read and map write troubleshooting
- [go] solve the fatal error of go: concurrent map writes map non concurrent security
- PostgreSQL sets the default value of the field to the current year