aspose file tools*
The moose likes Struts and the fly likes Struts validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts validation" Watch "Struts validation" New topic
Author

Struts validation

Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
My file is not validating please help i am giving all the details
validator-rules.xml
<?xml version="1.0" encoding="UTF-8"?>


<form-validation>



<global>


<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>
</global>
</form-validation>


validation.xml file




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>
<formset>
<form name="userForm">
<field property="username" depends="required">s

<msg name="required" key="err.user.username.required" />
</field>
<field property="pwd" depends="required,maxlength,minlength,mask">

<msg name="required" key="err.user.pwd.required" />
</field>
</form>
</formset>
</form-validation>



RegisterUser.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<html:html>
<head>
<title>RegisterUser</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>



<h2>Struts - Validator Example</h2>

RegisterUser.jsp
User Registeration Form





<html:errors/>


<html:form action="/Register" method="post" onsubmit="validateUserForm(this);">



<bean:message key="label.user.username" /> :
<html:text property="username" size="20"/>


<bean:message key="label.user.pwd" /> :
<html:text property="pwd" size="20"/>

<html:submit></html:submit>


</html:form>

</body>

</html:html>


Thankyou.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<html:html>
<head>
<title>ThankYou</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<body>

<h2>Struts - Validator Example</h2>

Thanks you for the registration

</body>


</html:html>

ApplicationResources.properties
label.user.name = Name
label.user.username = UserName
label.user.pwd = Password
err.user.username.required = Username is required.



err.user.pwd.required = Password is required.



RegisterAction.java
package com.cts.a.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
* @version 1.0
* @author
*/
public class RegisterAction extends Action

{

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward(); // return value

try {

// do something here

} catch (Exception e) {

// Report the error using the appropriate name and ID.
errors.add("name", new ActionError("id"));

}

// If a message is required, save the specified key(s)
// into the request for use by the <struts:errors> tag.

if (!errors.isEmpty()) {
saveErrors(request, errors);

// Forward control to the appropriate 'failure' URI (change name as desired)
forward = mapping.findForward("failure");

} else {

// Forward control to the appropriate 'success' URI (change name as desired)
forward = mapping.findForward("success");

}

// Finish with
return (forward);

}
}


UserForm.java
package com.cts.a.forms;
import org.apache.struts.validator.ValidatorForm;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionMapping;


public class UserForm extends ValidatorForm

{

private String username = null;

private String pwd = null;

public String getUsername() {
return username;
}


public void setUsername(String u) {
this.username = u;
}


public String getPwd() {
return pwd;
}


public void setPwd(String p) {
this.pwd = p;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {

// Reset values are provided as samples only. Change as appropriate.

username = null;
pwd = null;

}

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

return errors;

}
}

struts configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

<!-- Data Sources -->
<data-sources>
</data-sources>

<!-- Form Beans -->
<form-beans>
<form-bean name="UserForm" type="com.cts.a.forms.UserForm">
</form-bean>
</form-beans>

<!-- Global Exceptions -->
<global-exceptions>
</global-exceptions>

<!-- Global Forwards -->
<global-forwards>
</global-forwards>

<!-- Action Mappings -->
<action-mappings>
<action path="/Register" type="com.cts.a.actions.RegisterAction" validate="true" name="UserForm" scope="request">
<forward name="success" path="/ThankYou.jsp">
</forward>
<forward name="failure" path="/RegisterUser.jsp">
</forward>
</action>
</action-mappings>

<!-- Message Resources -->
<message-resources parameter="com.cts.a.resources.ApplicationResources"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/configure/validator-rules.xml,/validation.xml"/>
</plug-in>

</struts-config>

the page is directly going from RegisterUser.jsp to ThankYou.jsp


the error screen shot is

[11/9/12 5:34:33:660 GMT] 00000080 ServletWrappe I SRVE0242I: [a_ear] [/a] [action]: Initialization successful.
[11/9/12 5:34:33:660 GMT] 00000080 VirtualHost I SRVE0250I: Web Module a has been bound to default_host[*:9081,*:80,*:9444,*:5060,*:5061,*:443].
[11/9/12 5:34:33:676 GMT] 00000080 ApplicationMg I WSVR0226I: User initiated module start operation request completed on Module, a.war, of application, a_ear
[11/9/12 5:34:33:676 GMT] 00000080 FileRepositor A ADMR0009I: Document cells/PC136324Node02Cell/applications/a_ear.ear/deltas/a_ear/delta-1352439271975 is created.
[11/9/12 5:34:33:676 GMT] 00000080 FileRepositor A ADMR0010I: Document cells/PC136324Node02Cell/applications/a_ear.ear/deployments/a_ear/deployment.xml is modified.
[11/9/12 5:36:47:055 GMT] 00000082 ApplicationMg I WSVR0227I: User initiated module stop operation requested on Module, a.war, of application, a_ear
[11/9/12 5:36:47:071 GMT] 00000082 ServletWrappe I SRVE0253I: [a_ear] [/a] [action]: Destroy successful.
[11/9/12 5:36:47:071 GMT] 00000082 ApplicationMg I WSVR0228I: User initiated module stop operation request completed on Module, a.war, of application, a_ear
[11/9/12 5:36:47:086 GMT] 00000082 ApplicationMg I WSVR0225I: User initiated module start operation requested on Module, a.war, of application, a_ear
[11/9/12 5:36:47:164 GMT] 00000082 WebGroup A SRVE0169I: Loading Web Module: a.
[11/9/12 5:36:47:242 GMT] 00000082 PropertyMessa I org.apache.commons.logging.impl.Jdk14Logger info Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
[11/9/12 5:36:47:274 GMT] 00000082 PropertyMessa I org.apache.commons.logging.impl.Jdk14Logger info Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
[11/9/12 5:36:47:367 GMT] 00000082 PropertyMessa I org.apache.commons.logging.impl.Jdk14Logger info Initializing, config='com.cts.a.resources.ApplicationResources', returnNull=true
[11/9/12 5:36:47:398 GMT] 00000082 ValidatorPlug I org.apache.commons.logging.impl.Jdk14Logger info Loading validation rules file from '/WEB-INF/configure/validator-rules.xml'
[11/9/12 5:36:47:430 GMT] 00000082 ValidatorPlug I org.apache.commons.logging.impl.Jdk14Logger info Loading validation rules file from '/WEB-INF/configure/validation.xml'
[11/9/12 5:36:48:475 GMT] 00000082 ValidatorPlug E org.apache.commons.logging.impl.Jdk14Logger error Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:372)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:233)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:220)
at java.net.Socket.connect(Socket.java:536)

the main error is connection refused ,can anyone help me please



Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
I am getting a warning in line starting http that connection problem failed to validate
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
Can anyone please reply
ValidatorPlug E org.apache.commons.logging.impl.Jdk14Logger error Connection refused: connect
can anyone please help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts validation