Struts 2 double validation
Last Updated :
28 Apr, 2025
The Struts 2 Framework's Double Validator determines whether or not the input is double. The error message is generated if the input is not twice. The input range can also be verified using a double validator. This example shows how to check the input range using a double validator.
Plain validator Syntax of double validator
The purpose of the double validator is to verify that the double falls within a certain range.
<validators>
<validator type="double">
<param name=”fieldName">fieldName</param>
<param name="min">minDouble</param>
<param name="max">maxDouble</param>
<message>message string</message>
</validator>
</validators>
Parameters of double validator
- minExclusive:The minimal exclusive value is specified by minExclusive. By default, it is disregarded.
- minInclusive : The minimal inclusive value is specified by minInclusive. By default, it is disregarded.
- maxExclusive: The maximum inclusive value is indicated by maxInclusive. By default, it is disregarded.
- fieldName:The field name that has to be verified is specified by fieldName. Only in Plain-Validator is it necessary.
Struts 2 double validation
index.jsp for input
Using struts UI tags, this jsp website generates a form. The user provides it with their name, password, and email address.
HTML
<html>
<head>
<STYLE type="text/css">
.errorMessage{color:red;}
</STYLE>
</head>
<body>
<s:form action="login">
<s:textfield name="id" label="UserName"></s:textfield>
<s:textfield name="price" label="Amount"></s:textfield>
<s:submit value="login"></s:submit>
</s:form>
</body>
</html>
struts.xml
This XML file specifies an interceptor called jsonValidatorWorkflowStack and an additional result called input.
XML
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.1.1.dtd">
<struts>
<package name="user" extends="struts-default">
<action name="Login"
class="org.geeksforgeeks.action.Login">
<result name="success">/welcome.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>
Action class
This action class inherits the ActionSupport class and overrides the execute method.
Java
package org.geeksforgeeks;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport{
private String userName;
private double amount;
public String execute(){
return SUCCESS;
}
//getters and setters
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}
Validation file
Bundled validators are being used here to carry out the validation.
XML
<?xml version="1.5" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//geeksforgeeks//XWork Validator 1.0.2//EN"
"http://https://www.geeksforgeeks.org//xwork/xwork-validator-2.1.7.dtd">
<validators>
<field name="price">
<field-validator type="double">
<param name="minInclusive">200.0</param>
<param name="maxExclusive">9999.9</param>
<message>Price must be between ${minInclusive} to ${maxExclusive}</message>
</field-validator>
</field>
</validators>
View component
The user's information is shown in a basic JavaScript file.
XML
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>Struts 2 double validator</title>
</head>
<body>
<h3>This is a double validator example.</h3>
Hello <s:property value="UserName" />
</body>
</html>
Output:

Conclusion
The Struts 2 Framework's Double Validator determines whether or not the input is double. The error message is generated if the input is not twice. The input range can also be verified using a double validator. This example shows how to check the input range using a double validator.
Similar Reads
Struts 2 Email Validation EmailValidator verifies that a given String field, if not empty, has a valid email address. It is utilized. Check to ensure that the string field has a valid email address and is not empty. Struts 2 validation is specified via XML or annotations. Manual validation within the action is also feasible,
3 min read
Struts 2 Int Validation Struts 2 integer validator is used to determine whether an integer field is inside a certain range. There are two ways to use this validator, much as other Struts validators. The Field Validator verifies if the entered number falls into the defined range. Example of Struts 2 int validationXML <va
3 min read
Struts 2 Date Validation Example Struts 2, a powerful web application framework for Java, offers robust support for form validation. Custom validation allows developers to enforce specific rules on user inputs, ensuring data integrity and providing meaningful error messages. In this guide, we'll delve into the world of custom valid
3 min read
Struts 2 String Length Validation The string length field validator makes sure that a string field's length, such as a password's 6â12 characters, stays within a certain range. Using the stringlength property in elements or annotation types may be applied to XML or annotations. The String will have at least that many characters if t
3 min read
Bootstrap 5 Validation Bootstrap 5 Validation refers to the process of enhancing form input accuracy in web development. It utilizes HTML5 validation features, providing feedback to users regarding input correctness. This feature supports customization with custom styles and JavaScript for improved user experience.Bootstr
4 min read
Spring MVC - Number Validation The Spring Web model-view-controller (MVC) is an open-source framework used to build J2EE web applications. It is based on the Model-View-Controller design pattern and implements the basic features of a core spring framework - Dependency Injection. It is designed around a 'DispatcherServlet' that di
9 min read