This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
    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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

problems in validation part of struts 2

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!