Struts2 custom tag (JSP view) for graphic Verification

Source: Internet
Author: User
Tags tld

Let's take a look at the comments on the component label on the official website: DescriptionRenders an custom UI widget using the specified templates. additional objects can be passed in to the template using the param tags. freemarker: Objects provided can be retrieve from within the template via $ parameters. paramname. jsp: Objects provided can be retrieve from within the template via <s: property value = "% {parameters. paramname} "/> In the bottom JSP and Velocity samples, two parameters are being passed in to the component. from within the component, they can be accessed as:-Freemarker: $ parameters. get ('key1') and $ parameters. get ('key2') or $ parameters. key1 and $ parameters. key2 Jsp: <s: property value = "% {parameters. key1} "/> and <s: property value =" % {'parameters. key2 '} "/> or <s: property value =" % {parameters. get ('key1')} "/> and <s: property value =" % {Parameters. get ('key2')} "/> Currently, your custom UI components can be written in Velocity, JSP, or Freemarker, and the correct rendering engine will be found based on file extension. remember: the value params will always be resolved against the ValueStack so if you mean to pass a string literal to your component, make sure to wrap it in quotes I. e. value = "'value1 '" otherwise, the value sta Ck will search for an Object on the stack with a method of getValue1 (). (now that I 've written this, I'm not entirely sure this is the case. I shoshould verify this manana) If Jsp is used as the template, the jsp template itself must lie within the webapp itself and not the classpath. unlike Freemarker or Velocity, JSP template cocould not be picked up from the classpath. templateDir and theme attribut EThe final path to the template will be built using the templateDir andtemplate attributes, like $ {templateDir}/$ {theme}/$ {template }. if for example your component is under/components/html/option. jsp, you wowould have to set templateDir = "components", theme = "html" and template = "options. jsp ". for any Struts tag that you use in your component, make sure that you set its templateDir = "template "-------- Login self. tld: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE taglib PUBLIC "-// Sun Microsystems, Inc. // dtd jsp Tag Library 1.2 // EN "" http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd "> <Taglib> <tlib-version> 1.0 </tlib-version> <jsp-version> 1.2 </jsp-version> <short-name> map </short-name> <tag> <name> self </name> <tag-class> servlet. selfDefinationTag </tag-class> <body-content> JSP </body-content> </tag> </taglib> meaning: This is a JSP template file that defines the self tag, the self tag processing class is SelfDefinationTag. SelfDefinationTag. jsp: [html] <% @ page language = "java" pageEncoding = "gb2312" %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> <% @ taglib prefix = "s" uri = "/struts-tags" %>

Related Article

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.