Struts2 framework study notes 7: struts2 tag, struts2 Study Notes

Source: Internet
Author: User

Struts2 framework study notes 7: struts2 tag, struts2 Study Notes

Three labels:

1. JSP: script. Expired to replace servlet

2. JSTL: Standard tag Library (core, format, SQL, xml). Only core libraries are eliminated.

3. Struts2 tag Library: Developed by the Struts2 Development Team, with more powerful functions

 

Struts2 labels include common labels and UI labels.

Common Tag: Control tag, data tag

UI Tag: Form tag, non-form tag

 

 

Prepare some data:

        List<String> list = new ArrayList<>();        list.add("tom");        list.add("jerry");        list.add("jack");        list.add("rose");                ActionContext.getContext().put("list", list);

 

Common tag example:

<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib prefix =" s "uri ="/struts-tags "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 

 

Form tags (not commonly used ):

<! -- Struts2 form tag --> <! -- Benefit 1: a set of built-in styles. --> <! -- Benefit 2: Automatic Echo, based on the attributes in the stack --> <! -- Theme: specify the form subject xhtml: default simple: No topic --> <s: form action = "Demo3Action" namespace = "/" theme = "xhtml"> <s: textfield name = "name" label = "username"> </s: textfield> <s: password name = "password" label = "password"> </s: password> <s: radio list = "{'male', 'female '}" name = "gender" label = "gender"> </s: radio> <s: radio list = "# {1: 'male', 0: 'female '}" name = "gender" label = "gender"> </s: radio> <s: checkboxlist list = "# {2: 'Smoking ', 1: 'drinking', 0: 'playing game'}" name = "habits" label = "hobbies"> </s: checkboxlist> <s: select list = "# {2: 'Junior College ', 1: 'undergraduate', 0: 'master'} "headerKey =" "headerValue =" --- Please select --- "name =" edu "label =" "> </s: select> <s: file name = "photo" label = "Recent"> </s: file> <s: textarea name = "desc" label = "Personal Profile"> </s: textarea> <s: submit value = "submit"> </s: submit> </s: form> <s: actionerror/>

Action:

Package tag; import com. opensymphony. xwork2.ActionSupport; public class Demo3Action extends ActionSupport {private String name; public String execute () throws Exception {System. out. println (name); this. addActionError ("error"); return SUCCESS;} public String getName () {return name;} public void setName (String name) {this. name = name ;}}

 

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.