Web Custom Labels

Source: Internet
Author: User

1: Why do I need a custom label?

When the JSP's built-in tags and tags in the JSTL tag library don't meet the requirements, developers are required to customize the label.

2: First introduce our web small configuration

<?xml version= "1.0" encoding= "UTF-8"? ><taglib xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http:/ /www.w3.org/2001/xmlschema-instance "xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http://java.sun.co M/xml/ns/javaee/web-jsptaglibrary_2_1.xsd "version=" 2.1 "><description> <! [Cdata[security tags]]></description><tlib-version>1.0</tlib-version><short-name> Security</short-name><uri>http://www.springsecurity.org/jsp</uri><tag> <description > <! [Cdata[authorize tag]]> </description> <name>authorize</name> <tag-class> cn.st Ruts.util.AuthorizeTag </tag-class> <body-content>JSP</body-content> <attribute> & Lt;name>url</name> <required>false</required> &LT;RTEXPRVALUE&GT;TRUE&LT;/RTEXPRVALUE&G        T <type>java.lang.String</type> &LT;/attribute></tag></taglib>   

3: Tool class

public class Authorizetag extends Bodytagsupport {//You provide a user name, I give a user a set of permissions, and the operation is in the right DAO private Iprivilegedao    Privilegedao;    Private String URL;      Public String GetURL () {return URL;      } public void SetUrl (String url) {url = URL; } @Override public int doStartTag () {//If the URL is not empty, the URL is displayed, otherwise the IF (null! = URL) {Getuserda        O (); HttpServletRequest request = (HttpServletRequest) pagecontext.getrequest ();        UserInfo info= (UserInfo) request.getsession (). getattribute ("UserInfo");        list<privilege> list = Privilegedao.fimdallprivilegebyuserid (Info.getuserid ());  for (Privilege item:list) {if (Item.geturl (). Equals (URL)) {//render the label correctly return eval_body_include; }}} return this.      Skip_body; }public void Getuserdao () {Webapplicationcontext ApplicationContext =   Webapplicationcontextutils.getwebapplicationcontext (Pagecontext.getservletcontext ()); privilegedao= (Iprivilegedao) ApplicationContext.Getbean ("Iprivilegedao");} 

4:jsp

Introduce our web-customized links <% @taglib prefix= "Custom" uri= "http://www.springsecurity.org/jsp"%>// Click to get the table with the URL attribute in our column if his URL is not empty, display our "Add role" <custom:authorize url= "/role/addrole" ><a href= "#" > Add role </a></custom:authorize>

  

  

Web Custom Labels

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.