`

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自定义标签知识点详解 #### 一、概述 JSP(JavaServer Pages)是一种基于Java技术的服务器端动态网页开发技术。JSP自定义标签则是为了提高JSP页面的可读性和重用性而引入的一个重要特性。通过自定义标签,...

    jsp自定义标签实例.doc

    ### JSP自定义标签概述及实现 #### 一、引言 JSP (JavaServer Pages) 是一种基于Java技术的标准,用于开发动态Web应用程序。它允许开发者将Java代码嵌入到HTML页面中,从而实现动态内容的生成。为了提高代码的复用...

    自定义EL函数

    在Java Web开发中,Expression Language(EL)是一种强大的表达式语言,用于在JSP页面、JSF组件或者Servlet中访问和操作JavaBeans属性。EL提供了一种简洁的方式来获取和设置对象的属性,以及调用对象的方法。然而,...

    Tomcat+JSP经典配置实例

    ### Tomcat + JSP 经典配置实例详解 #### 一、开发环境配置 ##### 第一步:下载 J2SDK 和 Tomcat 对于初次接触 Java Web 开发的学习者来说,搭建一个可靠的开发环境至关重要。首先,我们需要下载 Java 2 Standard...

    jeasyui-app-crud1

    《基于jQuery EasyUI的CRUD应用实例解析》 在当今的Web开发中,快速构建用户界面(UI)已经成为一项重要任务。jQuery EasyUI提供了一种高效的方法,它是一个基于jQuery的UI框架,可以帮助开发者轻松创建功能丰富的...

    Java Tomcat面试题

    2. 使用Manager App控制台部署,在tomcat主页点击“Manager App”进入应用管理控制台,可以指定一个web应用的路 径或war文件。 3. 修改conf/server.xml文件部署,修改conf/server.xml文件,增加Context节点可以部署...

    struts2 项目实例

    默认的拦截器栈包含了如Validation、I18n、Prepare等拦截器,可以根据需求添加自定义拦截器。 在实际开发中,Struts2还有许多其他功能,如类型转换、结果映射、插件机制等。通过这个"Struts2App"实例,你可以学习...

    bookstore实例

    **AngularJS:构建BookStore实例** AngularJS,作为一款强大的前端JavaScript框架,以其数据双向绑定、模块化和指令系统等特点,极大地简化了Web应用程序的开发。在这个"bookstore"实例中,我们将深入探讨如何利用...

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

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

    struts2 struts2.0.9 实例 app下载

    最后,设计视图页面,如JSP或FreeMarker模板,使用OGNL来显示Action中的数据。 总之,Struts2.0.9是一个强大的Java web开发工具,它的MVC模式、拦截器、OGNL表达式等特性使得开发过程更加简洁高效。通过下载并研究...

    Spring MVC入门实例

    **Spring MVC 入门实例详解** Spring MVC 是 Spring 框架的一个重要模块,用于构建 Web 应用程序。它提供了模型-视图-控制器(MVC)架构,帮助开发者将业务逻辑、数据处理和用户界面分离,实现更加清晰的代码结构。...

    十天学会JAVA,JSP学习系列教程

    第四天,教程涵盖了Orion下自定义Tag的使用,这是JSP的一个强大特性,允许创建自定义标签库,提高代码复用性和可读性。通过实践,学生将学会如何设计和实现自己的JSP标签。 第五天,学习内容扩展到了JSP生成JPEG...

    jsp 科技企业信息管理系统

    3. **自定义标签库**:通过TLD(Tag Library Descriptor)文件,可以创建自定义的JSP标签,实现复用和封装复杂功能。 **四、课程设计要点** 1. **需求分析**:明确系统的需求,如信息录入、查询、修改、删除等功能...

    JSP环境配置全程图解手册

    每个JSP页面在运行时都会对应一个Servlet实例,并有九个内置对象,如`request`、`response`、`session`等。 - **JSP动作标签**: 使用`&lt;jsp:include&gt;`、`&lt;jsp:forward&gt;`、`&lt;jsp:useBean&gt;`等标签可以实现页面间的交互...

    JSP的tomcat操作视频

    2. **JSP指令**:包括`page`、`include`和`taglib`指令,它们分别用于设置页面属性、包含其他文件和导入自定义标签库。 3. **JSP动作**:如`&lt;jsp:include&gt;`、`&lt;jsp:forward&gt;`、`&lt;jsp:useBean&gt;`等,用于在页面间传递...

    web_xml(cusTag).txt

    根据提供的文件信息,我们可以得出这是关于Java Web应用配置文件`web.xml`的内容,特别是与自定义标签库(Custom Tag Library)相关的配置。接下来,我们将详细分析这个文件中的各个部分及其意义。 ### 一、XML声明...

    java编写struts2实例

    常见的结果类型有`dispatcher`,它用于转发到JSP页面,或者`stream`,用于下载文件。 5. **OGNL(Object-Graph Navigation Language)**:Struts2使用OGNL作为默认表达式语言,用于在Action和视图之间传递数据。...

    tomcat7.0 jsp

    JSP的核心概念包括JSP页面、指令、脚本元素、表达式、动作和自定义标签。在Tomcat 7.0中,JSP 2.2规范被支持,引入了若干新特性,如EL(Expression Language)的改进,以及对注解的支持。 首先,让我们深入了解一下...

    jsp 例子....................

    4. **JSP生命周期**:每个JSP页面在服务器上都有一个从加载到销毁的生命周期,包括翻译、编译、加载、初始化、服务和销毁六个阶段。在服务阶段,每次HTTP请求都会创建一个Servlet实例来处理请求。 5. **JSP和...

Global site tag (gtag.js) - Google Analytics