File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes problems in validation part of struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply locked New topic

problems in validation part of struts 2

Manish Shinde
Ranch Hand

Joined: Mar 30, 2011
Posts: 39
I m facing some problems in validation part of the struts 2

I have created some login application where I want validate to user name and password.

Here is the code.

<s:a href="EmployeeLogin.action">Employee Login Application</s:a>

2) EmployeeLogin.jsp
<div id="global">
<h3 align="center">Employee Login</h3>
<s:form action="Login" validate="true">
<table align="center">
<tr> <td><s:textfield name="userName" label="User Name" </td> </tr>
<tr><td><s:password name="password" label="Password" /></td></tr>
<tr><td><s:submit/></td> </tr>

3)Action Class –
package employee;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport{
private String userName;
private String password;

public String getPassword() {
return password;

public void setPassword(String password) {
this.password = password;

public String getUserName() {
return userName;

public void setUserName(String userName) {
this.userName = userName;

public String doLogin() {
if (this.userName.equals("Tom") && this.password.equals("Tom")) {
return "success";
} else {
return "error";

<constant name="struts.devMode" value="true" />
<include file="employee.xml"/>

<package name="employee" namespace="/JSP" extends="struts-default" >
<action name="EmployeeLogin">

<action name="Login" class="employee.Login" method="doLogin">
<result name="success">
<param name="location">/JSP/LoggedIn.jsp</param>
<result name="error">/JSP/EmployeeLogin.jsp</result>




<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE validators PUBLIC 'PUBLIC:-//OpenSymphony Group//XWork Validator 1.0.2//EN'
<field name="userNAME">
<field-validator type="required">
<message>User Name is required </message>
<field name="password">
<field-validator type="required">
<message>Password is required </message>

When I go on EmployeeLogin.jsp and without putting user name & password I click on submit it should show message User Name is required and password is required
But this not working.Also not showing any kind of error.

I have put login-validation.xml in the place where struts.xml and employee.xml are.
Also I tried another way by putting login-validation.xml in place where is.
Still it is not working.

Your help will be appreciated.


Joe Ess

Joined: Oct 29, 2001
Posts: 9168

Please do not post the same question more than once. It causes confusion and duplication of effort as the community tries to help everyone.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: problems in validation part of struts 2
It's not a secret anymore!