tumblr counter

Struts 2 Validation Example

Struts 2 Validation Example explains about step by step example of Struts2 Validation With Eclipse

Apache Struts 2, is a popular Java Model-View-Contraller (MVC) framework, which is developed by merging WebWork and Struts 1.x web frameworks.

Struts 2 have lot off difference with struts 1, struts 2 have implemented with an idea of convention over configuration, it also have many annotations in order to increase the developer productivity.

Struts 2 provides in built validation features. You can see how to validate the fields in struts 2, on below example

Note

When you deploy your struts 2 web application, you may get FilterDispatcher is deprecated! Please use the new filters! warning message, this is because FilterDispatcher filter is deprecated since Struts version 2.1.3, you need to re-configure your application with StrutsPrepareAndExecuteFilter

Required Libraries
  1. JDK 6
  2. Eclipse 3.7
  3. struts-2.3.15.1

Following jar must be in classpath

  1. commons-fileupload-1.3.jar
  2. commons-io-2.0.1.jar
  3. commons-lang3-3.1.jar
  4. commons-logging-1.1.3.jar
  5. freemarker-2.3.19.jar
  6. javassist-3.11.0.GA.jar
  7. ognl-3.0.6.jar
  8. struts2-core-2.3.15.1.jar
  9. xwork-core-2.3.15.1.jar

You can see the project structure below

Struts 2 Validation Example

Register.jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<s:head />
</head>
<body>
	<s:form action="register" method="post">
		<s:textfield name="username" label="User Name" />
		<s:textfield name="age" label="Age" />
		<s:password name="password" label="Password" />
		<s:submit value="register" />
	</s:form>
</body>
</html>

RegisterSuccess.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
    <body>
        <h1>Register Success</h1>
    </body>
</html>












Struts 2 Validation Example Struts 2 Validation Tutorial With Eclipse Struts 2 Step By Step Validation Example

You might also like following tutorials :

Java Tutorial Apache CXF Tutorial Hibernate Tutorial Spring Tutorial Struts Tutorial
1 Comments on "Struts 2 Validation Example"
13.05.2014 15:57:57 hariharan
Its very useful for me.................