Download Free Java and all books

Pages

Sunday, 16 September 2012

struts if tag

Example for if tag
 
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 language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <s:form action="doLogin" method="post">
        <s:if test="%{p in test}">
  Inside If block
</s:if>
        <s:else>
  Inside Else block
</s:else>

    </s:form>
</body>
</html>
# add this code  into struts.xml (see ifelse example tag):
        <action name="doLogin" class="com.anna.action.testifelse">
            <result name="SUCCESS">/ifelse.jsp</result>
            <result name="error">/fail.jsp</result>
        </action>
 
# wex.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Struts2Example7</display-name>
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</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>

right click on ifelse.jsp -> Run As -> Run on server . see the answer.
Try this code u will get the solution of your problem ...if you any problem than send me a email at  or give comment..you will also join with me...

Saturday, 15 September 2012

Struts tag hierarchy



The Struts 2 Tags has been dividing  into two types as follow:













Struts Generic Tags
These tag is use to control the execution flow when pages are rendered. Another use of struts generic tags are data extraction.
Control Tags:
It is used for flow control, such as if, else and iterate.

Here are the list of Control Tags:

  • if , 
  • elseIf, 
  •  else, 
  • append,  
  •  genertator,  
  •  iterator , 
  • merge ,  
  •  subset .

Data Tags:

 These tags is using  for data manipulation or creation, such as bean, push, and i18n.

  •  a ,
  • action,
  •  bean ,
  •  data ,
  •  debug ,
  • i18u ,
  • include ,
  • param , 
  • push ,
  •  set ,
  •  text ,
  • url , 
  • property


 

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...