< logic:present > and < logic:notPresent > Tag Example in Struts 1.3
< logic:present > and < logic:notPresent > Tag Example in Struts 1.3
<logic:present /> Tag Example in Struts 1.3 the following tool are required for run this example
- JDK 1.5
- MyEclipse IDE
- Server Tomcat 6.0
- Struts 1.3 jar file
Directory Structure of LogicPresentTagExample in Struts 1.3 Using MyEclipse IDE
index.jsp
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html>
<head>
<title><bean:message key="label.title"/></title>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<html:link action="/presentTagAction.do" >
Struts 1.3 Present Tag Example
</html:link>
</body>
</html>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Maven Struts Examples</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config> <form-beans>
<form-bean name="presentTagForm" type="org.r4r.struts.PresentTagForm"/>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/presentTag" type="org.apache.struts.actions.ForwardAction" parameter="/index.jsp"/>
<action path="/presentTagAction" name="presentTagForm" type="org.r4r.struts.PresentTagAction">
<forward name="success" path="/success.jsp"/>
</action>
</action-mappings>
<message-resources parameter="org.r4r.struts.ApplicationResources" />
</struts-config>
PresentTagForm.java
package org.r4r.struts;
import org.apache.struts.action.ActionForm;
@SuppressWarnings("serial")
public class PresentTagForm extends ActionForm {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
PresentTagAction.java
package org.r4r.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class PresentTagAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception{
PresentTagForm presentTagForm=(PresentTagForm)form;
presentTagForm.setName("Kumar Bal Mukund");
return mapping.findForward("success");
}
}
ApplicationResources.properties
# Resources for parameter 'org.r4r.struts.ApplicationResources'
# Project Struts1.3_LogicPresentTagExample
label.title=Struts 1.3 < logic:present > and < logic:notPresent >tag Example
label.header=Struts 1.3 < logic:present > and < logic:notPresent >tag Example
success.jsp
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html>
<head>
<title><bean:message key="label.title"/></title>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<h4>
<logic:present name="presentTagForm" property="name">
The Student Name is Kumar Bal Mukund.
</logic:present>
<logic:notPresent name="presentTagForm" property="name">
The Student Name is not Present.
</logic:notPresent>
</h4>
</body>
</html>
Output
