aspose file tools*
The moose likes Struts and the fly likes HTTP Status 404 - Servlet action is not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "HTTP Status 404 - Servlet action is not available" Watch "HTTP Status 404 - Servlet action is not available" New topic
Author

HTTP Status 404 - Servlet action is not available

Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 98
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>

prasad chowdary
Greenhorn

Joined: Feb 18, 2012
Posts: 18
hi, send your login page code.
Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 98

<html:form action="/student" method="post">

Name: <html:text property="name" />

Address:<html:textarea property="address" />

Email Id: <html:text property="emailAddress" />

<html:submit /> <html:reset/>

</html:form>
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Lalitha,
Are there any errors in the application log? if any, post the error log. Have you tried debugging to see if it reaches the validate method?


Have Fun with Java
little,little.. little by little makes a lot..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Status 404 - Servlet action is not available