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

No comments: