I used to do ASP, and when I came across a similar component that was used by multiple pages, I wanted to use the ascx (user-defined component) to solve it, and that's what I wanted to do with Java.
The effect I have to do is as follows:
Implementation scenario: Tag mode (custom label)
1. First define your own tag
1<%@ tag body-content= "scriptless" pageencoding= "UTF-8"%>2<%@ attribute name= "table" required= "true"%>3<%@ attribute Name= "IDfield" required= "true"%>4<%@ taglib uri= "http://java.sun.com/jsp/jstl/fmt" prefix= "FMT"%>5<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>6<c:set var= "base" value= "${pagecontext.request.contextpath}"/>7<c:set var= "Typelist"/>8<script src= "<c:url value="/scripts/jquery/jquery.1.10.2.min.js "/>" ></script>9<form method= "POST" >Ten<div id= "Divrecomment" > One<fmt:message key= "Recomment.title"/> A -<select id= "recommendaction" name= "Recommendaction" > -<c:foreach items= "${recommenttype}" var= "T" > the<option value= "${t.key}" >${t.value}</option> -</c:forEach> -<select> - <input type= "button" onclick= "handlerecomment ();" +Value= ' <fmt:message key= "recomment.submit"/> 'class= "Btn btn-primary"/> -</div> +</form>
Recommend.tag
2. Using a custom Label
<%@ taglib prefix= "T" tagdir= "/web-inf/tags"%>
<t:recommend table= "" idfield= "" ></t:recommend>
3. Recommenttype Data Source: Use the HandleRequest in the controller that corresponds to the page
1 New Hashmap<string,string>(); 2 Recommenttype.put ("1", "Home"); 3 Recommenttype.put ("2", "other"); 4 Request.setattribute (Constants.recomment_type, Recommenttype);
HandleRequest
Styles attached to
1 #divRecomment {2 margin-left:12px; 3 }4#divRecomment Select{5 width:200px; 6 height:38px; 7 border:1px solid #cccccc; 8 }
Main.css
Appfuse: Adding custom page Components