Download Free Java and all books

Pages

Saturday, 15 September 2012

Struts 2 Control Tags






Struts 2 Control Tags
1] If else tag :
Struts 2 :- If, ElseIf and Else tags are used to perform basic condition checking for your link like other language.
Trying to build your project as above structure :
I am codding for some important  java and jsp codding as below you must be try to implement in your word:
ifelse.jsp : page
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>If Else Condition</title>
 </head>
 <body>
 <!-- For Boolean Value -->
 <s:if test="myBooleanValue">
 I am returning TRUE.<br/>
 </s:if>
 <s:else>
 I am returning FALSE.<br/>
 </s:else>

 <!--Here For String Value -->
 <s:if test="%{myStringValue!=null}">
 String is not null<br/>
 </s:if>
 <s:elseif test="%{myStringValue==null}">
 String is null<br/>
 </s:elseif>
 <s:else>
 String is null<br/>
 </s:else>

 <!-- Here For Object Value -->
 <s:if test="%{checkArrayList.size()==0}">
 Object Size is Zero<br/>
 </s:if>
 <s:else>
 Object Size is not a Zero<br/>
 </s:else>

 </body>
</html>

# IfElseConditionAction.java page

import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class IfElseConditionAction extends ActionSupport {
   
     private List<String> checkArrayList = new ArrayList<String>();
     private String myStringValue;
     private boolean myBooleanValue;
   
     public String execute() {
   
     checkArrayList.add("aoiblog1");
     checkArrayList.add("aoiblog2");
     checkArrayList.add("aoiblog3");
     checkArrayList.add("aoiblog4");
     checkArrayList.add("aoiblog5");
   
     myStringValue = "aoi blog";
   
     myBooleanValue = true;
   
     return SUCCESS;
     }
   
     public List<String> getCheckArrayList() {
     return checkArrayList;
     }
   
     public void setCheckArrayList(List<String> checkArrayList) {
     this.checkArrayList = checkArrayList;
     }
   
     public String getMyStringValue() {
     return myStringValue;
     }
   
     public void setMyStringValue(String myStringValue) {
     this.myStringValue = myStringValue;
     }
   
     public boolean isMyBooleanValue() {
     return myBooleanValue;
     }
   
     public void setMyBooleanValue(boolean myBooleanValue) {
     this.myBooleanValue = myBooleanValue;
     }
   
    }
 

# web.xml page

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

 <filter>
 <filter-name>struts2</filter-name>
 <filter-class>
 org.apache.struts2.dispatcher.FilterDispatcher
 </filter-class>
 </filter>
 <filter-mapping>
 <filter-name>struts2</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <welcome-file-list>
 <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 </web-app>

#struts.xml  page:

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
 <constant name="struts.devMode" value="true" />

 <package name="struts2" extends="struts-default" namespace="/">
 <action name="ifElseAction">
 <result>/ifelse.jsp</result>
 </action>
 </package>
</struts>
after that run the ifelse page page by right clicking on it select Run As -> Run on server and see the magic .all the best. if youe hava any problem tha suggeset your comment on this blog  or u can mail me at mailme_mukesh@rediffmail.com
thank you...

No comments: