App问题审核 - jsp页面判断根据是否有图片决定是否显示,自定义标签实例

本文介绍了一种自定义标签的方法,用于判断消息内容中是否包含图片,并展示了如何在JSP页面上使用该标签来呈现相应的图标提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主要结构:
1.MessageHaveImageTag.java 判断内容是否有图片的自定义标签类.
2.myland.tld 自定义文件.
3.messageQueryList.jsp 显示页面.
显示效果:

[img]http://dl2.iteye.com/upload/attachment/0123/4221/928093a4-2eb1-3c19-9019-c6a82ae95e32.png[/img]

MessageHaveImageTag.java

package com.myland.framework.tags;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.WebApplicationContext;

import com.myland.framework.util.collections.ListUtil;
import com.myland.jp.common.service.MessageImageService;
import com.myland.pojo.MessageImage;

/**
*
* @author lengzl
* @email lengzhuolin@anjia365.com
* @create 2015年7月30日 下午4:59:42
*/
public class MessageHaveImageTag extends TagSupport{

private static final long serialVersionUID = -5234128142635788254L;

/**
* 信息id
*/
private String messageId ;

/**
* 存在图片返回1 不存在则返回0
*/
public int doStartTag() throws JspException {

try {
WebApplicationContext appContext = (WebApplicationContext) pageContext.getServletContext().getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
MessageImageService messageImageService = (MessageImageService) appContext.getBean("messageImageService");
String html = "0";

if(StringUtils.isNotBlank(messageId)){
List<MessageImage> messageImages = messageImageService.getMdListByPid(messageId);
if(ListUtil.isNotEmpty(messageImages)){
html = "1";
}
}
pageContext.getOut().write(html);// 标签的返回值

} catch(Exception e) {
throw new JspTagException("封装可编辑标签出现异常");
}
return EVAL_BODY_INCLUDE;
}

/**
*
*/
public int doEndTag() throws JspException {
return EVAL_PAGE;
}

public String getMessageId() {
return messageId;
}


public void setMessageId(String messageId) {
this.messageId = messageId;
}

}



myland.tld

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>myland</shortname>

<!-- 分页标签 -->
<tag>
<name>page</name>
<tagclass>com.myland.framework.tags.PageTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>pagination</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>showType</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>

<!-- 显示系统配置的基本信息 -->
<tag>
<name>base</name>
<tagclass>com.myland.framework.tags.BaseInfoTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>node</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<!-- 将文本设置可编辑标签 -->
<tag>
<name>edit</name>
<tagclass>com.myland.framework.tags.EditTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>message</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>url</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>paramName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>type</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<!-- 权限标签 -->
<tag>
<name>adminx_auth</name>
<tagclass>com.lecheng.framework.tags.AuthTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>action</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<!-- 取字典信息标签 -->
<tag>
<name>dic</name>
<tagclass>com.myland.framework.tags.DicTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>code</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>defaultValue</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>

<!-- 截取字符串标签 -->
<tag>
<name>str</name>
<tagclass>com.myland.framework.tags.StrTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>str</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>length</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>mark</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>markLength</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>

<!-- 获取缓存中的string类型的值 -->
<tag>
<name>cache</name>
<tagclass>com.myland.framework.tags.CacheTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>cacheType</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>key</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<!-- 列表序号 -->
<tag>
<name>index</name>
<tagclass>com.myland.framework.tags.PageIndexTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>qc</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>step</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<tag>
<name>cookie</name>
<tagclass>com.myland.framework.tags.CookieTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<!-- 根据messageid 判断是否存在图片.使用到的★★ -->
<tag>
<name>isHaveMessageImage</name>
<tagclass>com.myland.framework.tags.MessageHaveImageTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>messageId</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

</taglib>

messageQueryList.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/adminx/commonAll.js"></script>

<script type="text/javascript">

$(document).ready(function(){
// 进入页面时候title不在,查询时候的title不为空,
if($.trim("${qc.conditionsObj.title}")!=""){
$("#title").val("${qc.conditionsObj.title}");
}

});
</script>

<div id="showMessage" class="ui_tb">
<table id="tab" class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tr>
<!-- <th>创建人</th> -->
<th nowrap="nowrap">创建时间</th>
<th nowrap="nowrap">创建标题</th>
<th nowrap="nowrap">创建内容</th>
<th nowrap="nowrap">操作</th>
</tr>
<c:choose>
<c:when test="${empty messages}">
<tr>
<td colspan="6" style="text-align: center">无相关记录</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${messages }" var="mes" varStatus="status">
<tr>
<%-- <td>${mes.crtPerson}</td> --%>
<td>${mes.crtTime }</td>
<td>${mes.title }</td>
<td>
${mes.cont }
<a href="javascript:view('${mes.id }','${mes.status }')">
<c:set scope="page" var="isHave">
<!-- 自定义标签的判断★ -->
<myland:isHaveMessageImage messageId="${mes.id}"></myland:isHaveMessageImage>
</c:set>
<c:if test="${isHave==1}">
<img alt="" src="${pageContext.request.contextPath }/images/adminx/common/img.jpg" style="border: 0px;" width="15"/>
</c:if>
</a>
</td>
<td>
<span class="chakan">
<%-- -新建时候可以看到审核 --%>
<c:if test="${mes.status == '0' }">
<a href="javascript:audit('${mes.id }')" class="edit">审核</a>
</c:if>
<a href="javascript:viewDetailInfo('${mes.id }')">回复明细</a> <%--,'${qc.pagination.pageNum}' --%>
</span>

</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
<br>
<div><myland:page pagination="${qc.pagination}" showType="002"/></div>
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值