12:21 am - Monday May 1, 2017

Struts logic match logic notMatch example program

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Project Structure: 

 

 

 

 

 

 

 

 

 

 

 

 

 

JAR Files:  


 

 

 

 

 

 

 

LogicMatchAction.java:

package com.candidjava;

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 LogicMatchAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Match m = (Match) form;
		String s = m.getEmail();
		request.setAttribute("email", s);

		return mapping.findForward("success");
	}

}

Match.java:

package com.candidjava;

import org.apache.struts.action.ActionForm;

public class Match extends ActionForm {
	private String email = "kalaicse@candidjava.com";

	public String getEmail() {
		return email;
	}

	public String setEmail(String email) {
		return this.email = email;
	}

}

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>

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

		<init-param>
			<param-name>debug</param-name>
			<param-value>2</param-value>
		</init-param>
		<init-param>
			<param-name>detail</param-name>
			<param-value>2</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>welcome.jsp</welcome-file>

	</welcome-file-list>

	<taglib>
		<taglib-uri>/struts-html.tld</taglib-uri>
		<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
	</taglib>
	<taglib>
		<taglib-uri>/struts-bean</taglib-uri>
		<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
	</taglib>
	<taglib>
		<taglib-uri>/struts-logic</taglib-uri>
		<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
	</taglib>

	<security-constraint>
		<web-resource-collection>
			<web-resource-name>My secure resources</web-resource-name>
			<description>Resources to be placed under security control.</description>
			<url-pattern>/private/*</url-pattern>
			<url-pattern>/registered/*</url-pattern>
		</web-resource-collection>
		<auth-constraint>
			<role-name>guest</role-name>
		</auth-constraint>
	</security-constraint>

	<login-config>
		<auth-method>BASIC</auth-method>
		<realm-name>WebApp</realm-name>
	</login-config>

	<security-role>
		<description>The role allowed to access our content</description>
		<role-name>guest</role-name>
	</security-role>

</web-app>

struts-config.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

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

<struts-config>
	<form-beans>
		<form-bean name="mat" type="com.candidjava.Match"></form-bean>
	</form-beans>
	<action-mappings>

		<action path="/LogicTest" type="com.candidjava.LogicMatchAction"
			name="mat">

			<forward name="success" path="/LogicMatchNotMatch.jsp" />

		</action>

	</action-mappings>

</struts-config>

welcome.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>
</head>
<body bgcolor="pink">
<html:form action="/LogicTest">
	<p>click <html:submit>here </html:submit> to retrieve details using
	&lt;logic:MatchNotMatch&gt;</p>
</html:form>

</body>
</html>

LogicMatchNotMatch.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@ taglib uri="/struts-html.tld" prefix="html"%>
<%@ taglib uri="/struts-logic" prefix="logic"%>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body bgcolor="pink">

<h2>Struts - &lt;logic:match&gt; & &lt;logic:notMatch&gt;</h2>

Email - kalaicse@candidjava.com
<br />
<br />

1. Is "cse" is a substring of the email? -
<logic:match name="email" value="cse">
	true
</logic:match>
<logic:notMatch name="email" value="cse">
	false
</logic:notMatch>

<br />
<br />

2. Is "cseABC" is a substring of the email? -
<logic:match name="email" value="cseABC">
	true
</logic:match>
<logic:notMatch name="email" value="cseABC">
	false
</logic:notMatch>

<br />
<br />

3. Is email start with "kalai"? -
<logic:match name="email" value="kalai" location="start">
	true
</logic:match>
<logic:notMatch name="email" value="kalai" location="start">
	false
</logic:notMatch>

<br />
<br />

4.. Is email start with "kalai"? -
<logic:match name="email" value="cse" location="start">
	true
</logic:match>
<logic:notMatch name="email" value="cse" location="start">
	false
</logic:notMatch>

<br />
<br />

5. Is email end with "com"? -
<logic:match name="email" value="com" location="end">
	true
</logic:match>
<logic:notMatch name="email" value="com" location="end">
	false
</logic:notMatch>

<br />
<br />

6. Is email end with "net"? -
<logic:match name="email" value="net" location="end">
	true
</logic:match>
<logic:notMatch name="email" value="net" location="end">
	false
</logic:notMatch>

</body>
</html>

OUTPUT:

DOWNLOAD+SOURCECODE

Filed in: Z-AStruts Codes

No comments yet.

Leave a Reply