下面將以權限的控制為例自定義一個標簽
一
<wxt:per uri="${pageContext
步驟
package cn
import java
import java
import java
import java
import javax
import javax
import javax
import cn
import cn
import cn
import cn
/**
*
* @說明 自定義標簽
*/
public class PerssionTag extends SimpleTagSupport {
//自定義標簽屬性
private String uri;
//接收標簽傳入的參數
public void setUri(String uri) {
this
}
@Override
public void doTag() throws JspException
//獲取用戶登陸後保存的Session
PageContext page = (PageContext) this
User user = (User) page
//如果用戶登陸
if(user != null) {
//用戶登陸判斷用戶權限
List<String> list = new ArrayList<String>();
//獲取用戶的角色
Set<Role> role = user
for(Role r:role) {
//獲取角色對應的權限
Set<Privilege> privilege = r
for(Privilege p:privilege) {
//獲取權限對應的資源
Set<Resource> res = p
for(Resource re:res) {
list
}
}
}
for(String ur:list) {
//判斷用戶的權限
if(ur
this
}
}
}
}
}
<?xml version="
<taglib xmlns=":xsi="
version="
xsi:schemaLocation="://java
<description><![CDATA["To make it easier to access dynamic data;
the Apache Struts framework includes a library of custom tags
The tags interact with the framework
to ensure that input is correct and output is localized
The Struts Tags can be used with JSP FreeMarker or Velocity
<display
<tlib
<short
<uri>/wxt</uri>
<tag>
<name>per</name><!
<tag
<body
<!
<attribute>
<name>uri</name><!
<required>true</required><!
<rtexprvalue>true</rtexprvalue><!
</attribute>
</tag>
</taglib>
在Jsp頁面導入標簽
<A href="mailto:%@taglib prefix=
運用標簽
<wxt:per uri="${pageContext
<a href="${pageContext
</wxt:per>
用戶權限包含uri資源的將會輸出標簽內容
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20257.html