Struts: Can not get Error Messages
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aakash_dodiya
Posted On:   Thursday, August 18, 2005 01:30 PM

I make one Action class which have like below //////////////////////// package app; import javax.servlet.http.*; import org.apache.struts.action.*; public final class SubmitAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { SubmitForm f = (SubmitForm) form; // get the form bean String lastname = f.getLastname(); String firstname = f.getFirstname(); String address = f.getAddress(); //f.validate(mapping,request); request.setAttribute("lastname", lastname.toUpperCas   More>>
			

I make one Action class which have like below

////////////////////////
package app;

import javax.servlet.http.*;
import org.apache.struts.action.*;


public final class SubmitAction extends Action
{


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

{

SubmitForm f = (SubmitForm) form; // get the form bean


String lastname = f.getLastname();
String firstname = f.getFirstname();
String address = f.getAddress();
//f.validate(mapping,request);
request.setAttribute("lastname", lastname.toUpperCase());
request.setAttribute("firstname", firstname.toUpperCase());
request.setAttribute("address", address.toUpperCase());



return (mapping.findForward("success"));
}
}
//////////////////////////////////

And Action Forward class like Below


package app;

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


public final class SubmitForm extends ActionForm {


private String firstname = null;
private String lastname = null;
private String address = null;


// ------------------------------------------------------ Properties
/////////First name//////////////
public String getFirstname()
{
return (this.firstname);
}

public void setFirstName(String firstname)
{
this.firstname = firstname;
}

/////////Last name//////////////
public void setLastname(String lastname)
{
this.lastname = lastname;
}
public String getLastname()
{
return (this.lastname);
}
/////////address //////////////
public String getAddress()
{
return (this.address);
}

public void setAddress(String address)
{
this.address = address;
}




public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

if ((firstname == null) || (firstname.length() < 1))
errors.add("firstname",
new ActionError("error.firstname.required"));

if ((lastname == null) || (lastname.length() < 1))
errors.add("lastname",
new ActionError("error.lastname.required"));

if ((address == null) || (address.length() < 1))
errors.add("address",
new ActionError("error.address.required"));

return errors;

}

} // End LogonForm

////////////////////////////////////

now In Struts-config.xml i have make Action mapping like this




path="/LogonSubmit"
type="app.SubmitAction"
name="submitForm"
scope="request"
validate="true"
input="/pages/Logon.jsp">

name="success"
path="/pages/Logon_a.jsp"/>

name="failure"
path="/pages/Logon_a.jsp"/>




////////////////////////
problem here is that i cant get error messages as per validation method. i test my application several times but there is still problem.
and also if i change the "success" and "failure" path attrubute to other page Logon_a.jsp In which I just simply print my first name and last name then also i can not get that page from action mapping in struts-config.html

i also put the tag in my main jsp page Logon.jsp

please help me
   <<Less
About | Sitemap | Contact