Action gets form submission data
<formMethod= "POST"Action= "./user/adduser.action"> <label for= "Name">Name:</label> <inputtype= "text"name= "Name"ID= "Name"> <inputtype= "Submit"Data-inline= "true"value= "Submit">
</form>
The action class defines a string variable, adding the Get () set () method.
Note: The variable name and the name attribute in the form label are the same.
By getting the value of a string variable, you can get the data submitted by the form. If the data submitted by the form is not of type string, the type converter needs to be defined.
PackageCom.wdl.user;Importjavax.servlet.http.HttpServletRequest;ImportOrg.apache.struts2.ServletActionContext;ImportCom.opensymphony.xwork2.ActionContext;ImportCom.opensymphony.xwork2.ActionSupport; @SuppressWarnings ("Serial") Public classAdduseractionextendsActionsupport {String name; PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } @Override PublicString Execute ()throwsException {httpservletrequest request=servletactioncontext.getrequest (); Request.setattribute ("Attribute", name);return"Success"; }}
Get Requset attribute in the action forwarding page
${requestscope.attribute}
Struts processes form data