File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes problem in struts2 validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem in struts2 validation" Watch "problem in struts2 validation" New topic
Author

problem in struts2 validation

Parthiban Thangaraju
Greenhorn

Joined: Oct 16, 2012
Posts: 12
Dear Friends,

I am facing a problem in validation the form. form is not validated. Kindly any one help me to solve this problem

login action

package com.vaannila.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.vaannila.model.Login;
public class LoginAction extends ActionSupport implements ModelDriven {

Login login=new Login();

public String execute() {

return SUCCESS;
}

public Object getModel(){
return login;
}
}

login

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.vaannila.model;

import com.opensymphony.xwork2.ActionSupport;

/**
*
* @author Meyyappan Muthuraman
*/
public class Login implements java.io.Serializable {

private String userName;
private String password;

public Login() {
}



/**
* @return the userName
*/
public String getUserName() {
return userName;
}

/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}

/**
* @return the password
*/
public String getPassword() {
return password;
}

/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
}

login.jsp

<%--
Document : index
Created on : Feb 28, 2009, 9:45:01 AM
Author : Meyyappan Muthuraman
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Page</title>
<s:head />
</head>
<body>
<s:actionerror/>
<s:form action="LoginAction">
<s:textfield name="userName" label="User Name" />
<s:password name="password" label="Password" />
<s:submit value="Login" />
</s:form>
</body>
</html>

validation.xml

<!DOCTYPE validators 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="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>

struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="LoginAction" class="com.vaannila.action.LoginAction">
<result name="input">/login.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

hi Parthiban,

Use code tags , Please. and let us know where you are excatly facing problem. Are you getting error or validation dosent fire.

Regards
jatan





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in struts2 validation