`

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

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



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>
  • 大小: 148.4 KB
分享到:
评论

相关推荐

    JSP 自定义标签实现数据字典的实例

    JSP 自定义标签实现数据字典的实例  1.关于JSP标签的好处就不再罗嗦 数据字典就是使用的下拉框,只要定义使用那个字典就会将这个字典可用的内容显示出来 显示字典时只要定义那个字典和属性值就可以显示出字典的...

    Java范例开发大全(全书源程序)

    实例14 判断输入的年份是否为闰年 26 实例15 抽奖活动 27 3.2 for语句 28 实例16 小九九乘法表 28 实例17 如何列出素数 29 实例18 Java中的递归 31 实例19 男生女生各多少人 32 实例20 求水仙花数 34 实例21...

    JAVA上百实例源码以及开源项目源代码

     Java实现HTTP连接与浏览,Java源码下载,输入html文件地址或网址,显示页面和HTML源文件,一步步的实现过程请下载本实例的Java源码,代码中包括丰富的注释,对学习有帮助。 Java实现的FTP连接与数据浏览程序 1个...

    JAVA上百实例源码以及开源项目

     Java实现HTTP连接与浏览,Java源码下载,输入html文件地址或网址,显示页面和HTML源文件,一步步的实现过程请下载本实例的Java源码,代码中包括丰富的注释,对学习有帮助。 Java实现的FTP连接与数据浏览程序 1个...

    Spring MVC自定义日期类型转换器实例详解

    Spring MVC自定义日期类型转换器实例详解  WEB层采用Spring MVC框架,将查询到的数据传递给APP端或客户端,这没啥,但是坑的是实体类中有日期类型的属性,但是你必须提前格式化好之后返回给它们。说真的,以前真没...

    JSTL详细标签库介绍

    那么:&lt;BR&gt;&lt;BR&gt;命令行APP/控制台APP(不基于GUI),当异常不能被“捕获”,那么该程序会运行默认异常处理程序,退出JAVA,若Applet或基于GUI的APP,当一个异常未被“捕获”,GUI在运行默认异常处理程序依然会显示,...

    深入浅出Struts 2 .pdf(原书扫描版) part 1

    如果某种操作在不同的地区有不同的结果,那它就是对地区敏感的(10cale-sensitive),例如,显示日期就是一种对地区敏感的操作,因为日期的显示格式应该顺应本地用户所在的国家或地区的语言习惯。以2007年8月15日为...

    基于SSH框架的BBS论坛JavaEE项目源码

    2.图片太大显示不全问题 3.会员组设置附件上线没有用以及其他相关设置无效 4.附件上传经常上传不了 5.发帖文字内容不能居中、居左、居右 编辑器字体、大小、插入图片、排序列表无效、左浮动、右浮动 6.用户...

    Struts2入门教程(全新完整版)

    一、准备工作及实例 3 1.解压struts-2.1.6-all.zip 3 2.六个基本包 3 3.初识struts2配置文件 4 (1).web.xml文件 4 (2).struts.xml文件 4 (3).struts.properties(参default.properties) 4 (4)struts-...

    Google Android SDK开发范例大全(第3版) 1/5

    3.24 判断手机操作系统版本是否允许运行程序 3.25 两个不同的程序彼此调用 3.26 指定安装应用程序迁移至SD卡 3.27 手机动态Layout主题随手势物换迁移 第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞 4.2 ...

    Google Android SDK开发范例大全(第3版) 4/5

    3.24 判断手机操作系统版本是否允许运行程序 3.25 两个不同的程序彼此调用 3.26 指定安装应用程序迁移至SD卡 3.27 手机动态Layout主题随手势物换迁移 第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞 4.2 ...

    Google Android SDK开发范例大全(第3版) 3/5

    3.24 判断手机操作系统版本是否允许运行程序 3.25 两个不同的程序彼此调用 3.26 指定安装应用程序迁移至SD卡 3.27 手机动态Layout主题随手势物换迁移 第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞 4.2 ...

    Java开发技术大全(500个源代码).

    HelloWorldApp.java 第一个用Java开发的应用程序。 firstApplet.java 第一个用Java开发的Applet小程序。 firstApplet.htm 用来装载Applet的网页文件 第2章 示例描述:本章介绍开发Java的基础语法知识。 ...

    java开源包101

    Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (&lt;jcaptcha:image label="Type the text "/&gt; ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码图片。 Java 命令行解析...

    ssh(structs,spring,hibernate)框架中的上传下载

    WEB-INF下的applicationContext.xml为Spring的配置文件,struts-config.xml为Struts的配置文件,file-upload.jsp为文件上传页面,file-list.jsp为文件列表页面。  本文后面的章节将从数据持久层->业务层->Web层的...

    java开源包4

    Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (&lt;jcaptcha:image label="Type the text "/&gt; ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码图片。 Java 命令行解析...

Global site tag (gtag.js) - Google Analytics