Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Status 404 - Servlet action is not available

 
Vidya Gupta
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, send your login page code.
 
Vidya Gupta
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<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
Posts: 329
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic