jsp标签02

UI标签(用户界面的数据控制)

out输出
@Override
 public int doStartTag() throws JspException {
  JspWriter out = pageContext.getOut();//流对象  拿到输入对象
  try {
   out.print(value.toString());//拿到value对象
  } catch (IOException e) {
   e.printStackTrace();
  }
  return SKIP_BODY;
 }
 

注1:JspWriter writer = pageContext.getOut();

select下拉框
/**
 * 1、值的传递  id、name
 * 2、数据源  items
 * 3、展示列与数据存储列与实体列的对应关系   textKey  textVal
 * 4、数据回显  selectedVal
 * 5、可能下拉框默认值(头标签) headerTextKey  headerTextVal
 * @author tt
 * */
public class SelectTag extends BodyTagSupport{
private static final long serialVersionUID = 1L;
private String id;
 private String name;
 private List<Object> items = new ArrayList<>();
 private String textKey;//textKey = id
 private String textVal;
 private String selectedVal;
 private String headerTextVal;
 private String headerTextKey;
 @Override
 public int doStartTag() throws JspException {
  JspWriter out = pageContext.getOut();//流对象
   try {
    out.print(toHTML());//调方法
   } catch (Exception e) {
    e.printStackTrace();
   }
  return super.doStartTag();
 }
 private String toHTML() throws Exception {
  StringBuffer sb = new StringBuffer();
  sb.append("<select id='"+id+"' name='"+name+"'>");
  if(!(headerTextKey==null||"".equals(headerTextKey)||
   headerTextVal == null|| "".equals(headerTextVal) )) {
   sb.append("<option selected value = '"+headerTextKey+"'>"+headerTextVal+"</option>");
  }
  String value;
  String html;
  for (Object obj : items) {
   Field textKeyField = obj.getClass().getDeclaredField(textKey);
   textKeyField.setAccessible(true);
   value = (String) textKeyField.get(obj);
   html = (String) PropertyUtils.getProperty(obj, textKey);
   if(value.equals(selectedVal)) {
    sb.append("<option selected value = '"+value+"'>"+html+"</option>");
   }else {
    sb.append("<option value = '"+value+"'>"+html+"</option>");
   }
  }
  sb.append("</select>");
  return sb.toString();
 }
 public SelectTag() {
  super();
 }
 

控制标签(业务逻辑处理时的数据控制)

if
private boolean test;//属性
@Override
 public int doStartTag() throws JspException {
  return test ?EVAL_BODY_INCLUDE: SKIP_BODY;如果test为true则为输出,如果test为false则为跳过主体。
 }

forEach

public class ForeachTag extends BodyTagSupport{
private static final long serialVersionUID = 1L;
private String var;
 private List<Object> items = new ArrayList<>();
 /**
  * 执行完这个方法的时候,var所代表的指针一定要向下移动一位;
  */
  @Override
 public int doStartTag() throws JspException {
  if(items.size() == 0) {
   return SKIP_BODY;
   }else {
   Iterator<Object> it = items.iterator();
   pageContext.setAttribute(var, it.next());
   pageContext.setAttribute("it", it);
   return EVAL_BODY_INCLUDE;
  }
 }
 @Override
 public int doAfterBody() throws JspException {
  Iterator<Object> it =(Iterator<Object>) pageContext.getAttribute("it");
  if(it.hasNext()) {
   pageContext.setAttribute(var,it.next());
   pageContext.setAttribute("it", it);
   return EVAL_BODY_AGAIN;
  }
  return super.doAfterBody();
 }

注1:page(pageContext)|request(…)|session(…)|application(…)
存储和交换数据

数据标签

数据标签就是用来存储数据和设置数据值的

set

private String var;
 private String value;
  @Override
 public int doStartTag() throws JspException {
  pageContext.setAttribute(var, value);//存储值
  return SKIP_BODY;//跳过主体
 }
 

建立z标签语言

<description>zking 1.1 core library</description>
  <display-name>zking core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>c</short-name>
  <uri>/zking</uri>//在jsp界面要调用的路径
   <tag>
    <name>set</name>
    <tag-class>com.zking.jsp.day2.SetTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <name>var</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
     <tag>
    <name>out</name>
    <tag-class>com.zking.jsp.day2.OutTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>
  ............

在页面调用
建立一个jsp文件,在文件开头调用z语言
<%@ taglib prefix=“z” uri="/zking" %>

<body>
 <z:set var="name" value="zhangsan"></z:set>
 <z:out value="${name }"></z:out>
 <z:if test="true">lisi</z:if>
 <z:if test="false">wanwu</z:if>//在用户界面wanwu不会展示出来,因为test的属性为false
 <%
  List list = new ArrayList();
  list.add(new Student("001","xiaocheng"));
  list.add(new Student("002","xiaoli"));
  list.add(new Student("003","xiaowang"));
  request.setAttribute("stus", list);
  <z:foreach items="${stus }" var="stu">
 ${stu.id },${stu.name }<br>
 </z:foreach>
 <z:select selectedVal="002" headerTextKey="-1" headerTextVal="===请选择===" textVal="name" items="${stus }" textKey="id"></z:select>
 </body>
 %>

注意:一定要在写助手类的时候写构造方法。
不然会报:java.lang.NoSuchMethodException:com.TT.jsp.day1.DemoTag.()

数据字典

含义:对数据的数据项、数据结构、数据流、数据存储、处理逻辑等进行定义和描述,其目的是对数据流程图中的各个元素做出详细的说明,

作用:是一种用户可以访问的记录数据库和应用程序元数据的目录。方便对用户界面进行改动。有利于程序员人和分析员和用户的通信。是分析阶段的工具

Chackbox

public class Checkbox extends BodyTagSupport{
private static final long serialVersionUID = 1L;
private String textKey;//传入值
 private String textVal;//显示值
 private List<Object> checkedVal=new ArrayList<>();//回显数据集合
 private List<Object> item=new ArrayList<>();//数据集合
public List<Object> getCheckedVal() {
  return checkedVal;
 }
 public void setCheckedVal(List<Object> checkedVal) {
  this.checkedVal = checkedVal;
 }
 public List<Object> getItem() {
  return item;
 }
 public void setItem(List<Object> item) {
  this.item = item;
 }
 @Override
 public int doStartTag() throws JspException {
  JspWriter out = pageContext.getOut();//流对象
   try {
   out.print(toHTML());//调方法
   } catch (Exception e) {
    e.printStackTrace();
   }
  return super.doStartTag();
 }
  public String toHTML() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
  StringBuffer sb=new StringBuffer();
  String value;
  String html;
  for (Object obj : item) {
   Field textKeyfield = obj.getClass().getDeclaredField(textKey);//获得对象
   textKeyfield.setAccessible(true);//打开权限
   value=(String)textKeyfield.get(obj);
   Field textValfield = obj.getClass().getDeclaredField(textVal);
   textValfield.setAccessible(true);
   html=(String)textValfield.get(obj);
   if(checkedVal.contains(value)) {
    sb.append("<input checked type='checkbox' value='"+value+"' />"+html+"");
   }
   else {
    sb.append("<input type='checkbox' value='"+value+"' />"+html+"");
   }
   }
  return sb.toString();
 }
 public String getTextKey() {
  return textKey;
 }
 public void setTextKey(String textKey) {
  this.textKey = textKey;
 }
 public String getTextVal() {
  return textVal;
 }
 public void setTextVal(String textVal) {
  this.textVal = textVal;
 }
 public Checkbox(String textKey, String textVal, List<Object> checkedVal, List<Object> item) {
  super();
  this.textKey = textKey;
  this.textVal = textVal;
  this.checkedVal = checkedVal;
  this.item = item;
 }
 public Checkbox() {
  super();
 }
 }

z语言定义

<tag>
    <name>checkbox</name>
    <tag-class>com.zking.jsp.day2.Checkbox</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <name>textKey</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <name>textVal</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
      <attribute>
        <name>item</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
     </attribute>
     <attribute>
        <name>checkedVal</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
     </attribute>
  </tag>

界面展示

<body>
<%
  List list = new ArrayList();
  list.add(new Student("1","xiaocheng","篮球"));
  list.add(new Student("2","xiaocheng","滑冰"));
  list.add(new Student("3","xiaocheng","看书"));
  list.add(new Student("4","xiaocheng","听歌"));
  List ls = new ArrayList();
  ls.add("1");
  ls.add("2");
  request.setAttribute("stus", list);
  request.setAttribute("ls", ls);
 %>
 <z:checkbox textVal="name" item="${stus }" textKey="id" checkedVal="${ls }"></z:checkbox>
</body>
乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值