日志文章

2007年10月08日 22:43:12

struts logic 标签使用之三

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<[url=mailto:%@page]%@page import="com.stu.bean.StudentBean"%>
<[url=mailto:%@page]%@page import="org.apache.struts.action.ActionErrors"%>
<[url=mailto:%@page]%@page import="org.apache.struts.action.ActionMessage"%>
<[url=mailto:%@page]%@page import="org.apache.struts.Globals"%>
<html>
<head>
  <base href="<%=basePath%>">
 
  <title>My JSP 'TestLogic1.jsp' starting page</title>
 
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
logic:empty使用:<br>
<%
ActionErrors errors = new ActionErrors();
errors.add("totallylost",new ActionMessage("application.totally.lost"));
request.setAttribute(Globals.ERROR_KEY,errors);
request.setAttribute("myerrors",errors);
request.setAttribute("emptyString","");
%>
<logic:empty name="emptyString">
The variable named emptyString is empty!<p>
</logic:empty>
<logic:notEmpty name="emptyString">
The variable named emptyString is empty!<p>
</logic:notEmpty><br>

<logic:present name="noSuchBean" property="noSuchProperty">
Both noSuchBean and noSuchProperty exist!<p>
</logic:present>
<logic:notPresent name="noSuchBean" property="noSuchProperty">
Either noSuchbean or noSuchProperty does not exist!<p>
</logic:notPresent>

<logic:present name="emptyString">
There is a JavaBean named "emptyString" .<p>
</logic:present>
<logic:notPresent name="emptyString" property="noSuchProperty">
EmptyString doesn't hava such a property named "noSuchProperty".<p>
</logic:notPresent>
<logic:present header="user-agent">
Yep,we got a user-agent header.<p>
</logic:present>
<logic:notPresent header="user-agent">
No,user-agent header does not exist.<p>
</logic:notPresent>

<logic:messagesPresent>
Yes,there are errors.<p>
</logic:messagesPresent>
<logic:messagesPresent name="myerrors">
Yes,there are errors in myerrors collection.<p>
</logic:messagesPresent>
<logic:messagesNotPresent message="true">
There are no normal messages.<p>
</logic:messagesNotPresent>


<logic:messagesNotPresent property="noSuchError">
There is no error named "noSuchError".<p>
</logic:messagesNotPresent>
<logic:messagesPresent property="totallylost">
There is an error named "totallylost".
</logic:messagesPresent>
</body>
</html>

Tags: struts   logic   标签  

类别: struts |  评论(0) |  浏览(946) |  收藏
发表评论