Struts processes form data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.