Reputation: 232
This is my controller Login.java
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {
private String userName;
private String password;
public Login() {
}
public String execute() {
return SUCCESS;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
This is my Login-Validation.xml
<?xml version="1.0"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="userName">
<field-validator type="requiredstring">
<message>User Name is required.</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="password.required" />
</field-validator>
</field>
</validators>
This is my struts.xml
<action name="NewLogin">
<result>login.jsp</result>
</action>
<action name="LoginAction" class="com.strut.Login">
<result name="success">success.jsp</result>
<result name="input">fail.jsp</result>
</action>
I am using struts2-core 2.5.16 as the maven plugin.
The issue is the controller is not considering my validation.xml. It directly passes to the execute method and goes to the success page.
I have placed the controller and validation xml within the same package.
Could someone help me with it? Thanks in advance.
Upvotes: 0
Views: 61
Reputation: 57
Your file that named "Login-Validation.xml" is error.
Solution:
1. The validation xml file should be named the "Login-validation.xml".
2. The <result name="input" >fail.jsp</result>
had been changed to <result name="input" >login.jsp</result>
. This will be better and logical.
Upvotes: 1