Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

problems in validation part of struts 2

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.

1)index.jsp
<ul>
<li>
<s:a href="EmployeeLogin.action">Employee Login Application</s:a>
</li>
</ul>

2) EmployeeLogin.jsp
</head>
<body>
<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>
</table>
</s:form>
</div>
</body>
</html>


3)Action Class –Login.java
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;
System.out.println(password);
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
System.out.println(userName);
}

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

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

5)employee.xml
<struts>
<package name="employee" namespace="/JSP" extends="struts-default" >
<action name="EmployeeLogin">
<result>/JSP/EmployeeLogin.jsp</result>
</action>

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

</package>

</struts>

6)login-validation.xml

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


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

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 Login.java is.
Still it is not working.


Your help will be appreciated.

Regards,
Manish


 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question more than once. It causes confusion and duplication of effort as the community tries to help everyone.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic