Struts2 learning notes 1-struts2 label Learning

Source: Internet
Author: User
Tags i18n

Struts2 tag

Finally, the struts2 tag is almost visible, but there are still a lot that are not very familiar. I learned it by combining the struts2 tutorial of Max and the reference document of Struts! Many of the notes are moved from Max's blog. However, there is no way to do it. We cannot do it, and we can only stand on the shoulders of others to learn !!

If, elseif, else tag

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

  

It is common sense that when parameters are passed through urls: struts2 encapsulates parameters of the same name passed by URLs into an array, in other words, we can upload two parameters with the same name in a URL (that is? Name = A & name = B); you can obtain the values of parameters # parameters. name [0] and parameters. name [1.

Include tag

  Included page:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="/struts-tags" prefix="s"%>this is the include page!!!

Include page:

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

Of course, the include tag of Struts can contain static dynamic pages!

I18n label
Description: loads the resource package to the value stack. It allows the text flag to access information of any resource package, not only the resource package associated with the current action.

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

  

Iterator label

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="/struts-tags" prefix="s"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  

This label is easy to understand.

Param label

The <s: param> tag of struts2 is complicated for me. The S: Param tag of struts2 mainly has two attributes: Name and value. If you want to enter the direct quantity in the value attribute, you can write as follows: <s: param name = "some" value = "% {'user'}"/>, you can also write: <s: Param name = "some"> User </s: param>. However, if the value is directly assigned, this value is not dynamically generated by action, but a character string specified by itself. Only the latter can be used.

Param Page code:

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

  

Paramaction page:

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

  

Frequently Used UI labels

<% @ Page contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "%> <% @ taglib prefix =" S "uri ="/Struts-tags "%> <% @ taglib prefix =" S "URI = "/Struts-tags" %> <% @ taglib prefix = "SX" uri = "/Struts-Dojo-tags" %> <HTML> 

  

These codes are directly copied from Max's blog. Originally, this is a complete example. I just tested the front-end display code. There is something worth attention here, but it is also reflected in the Code. This is the difference between struts2's more advanced version and lower version, I am not very clear about the specific version. The difference is about <s: datetimepicker>. When using <s: datetimepicker>, the struts2-dojo-plugin-2.2.1.jar must also be introduced in a higher version, you must also specify <% @ taglib prefix = "SX" uri = "/Struts-Dojo-tags" %>. If the experiment fails, consider whether this problem exists.

Struts-tags is a review here. It would be better if you work with a specific project. Continue to work !!!

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.