Hi,
I am new to
struts.. I am developing a student details login page.. After entering the details, it should redirect to success page or failure page if all the details are not provided.. But am getting "
servlet action not found" error after submitting the form.. Am unable to find the mistake.. Please suggest me about that error.
Thanks in advance..
StudentForm.java
--------------------
package info.student;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class StudentForm extends ActionForm
{
private
String name;
private String address;
private String emailAddress;
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setAddress(String address){
this.address=address;
}
public String getAddress(){
return this.address;
}
public void setEmailAddress(String emailAddress){
this.emailAddress=emailAddress;
}
public String getEmailAddress(){
return this.emailAddress;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors actionErrors = new ActionErrors();
try
{
if (name == null || name.length() == 0) {
actionErrors.add("name", new ActionMessage(
"name.required"));
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (address == null || address.length() == 0) {
actionErrors.add("address", new ActionMessage(
"address.required"));
}
}catch (Exception e) {
e.printStackTrace();
}
try{
if (emailAddress == null || emailAddress.length() == 0) {
actionErrors.add("emailAddress", new ActionMessage(
"emailAddress.required"));
}
}catch (Exception e) {
e.printStackTrace();
}
return actionErrors;
}
}
StudentAction.java
-----------------
package info.student;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class StudentAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
System.out.println("execute method");
StudentForm sf=(StudentForm)form;
String sname=sf.getName();
String sadd=sf.getAddress();
String semail=sf.getEmailAddress();
System.out.println("values returned");
if(sname==null || sadd==null || semail==null){
System.out.println("redirecting to failure page");
return mapping.findForward("failure");
}
else{
System.out.println("redirecting to success page");
return mapping.findForward("success");
}
}
}
struts-config.xml
-----------------
<form-beans>
<form-bean name="sdetails" type="info.student.StudentForm">
</form-bean>
</form-beans>
<action-mappings>
<action path="/student" type="info.student.StudentAction" name="sdetails" scope="request" validate="true">
<forward name="success" path="/loginsuccess.jsp"></forward>
<forward name="failure" path="/loginfailure.jsp"></forward>
</action>
</action-mappings>