GeeCON Prague 2014*
The moose likes Struts and the fly likes Struts2 action method HTTP 500 error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 action method HTTP 500 error" Watch "Struts2 action method HTTP 500 error" New topic
Author

Struts2 action method HTTP 500 error

titli das
Greenhorn

Joined: May 05, 2013
Posts: 7
Hi,

I need some help with my struts2 application.

In struts.xml I have defined

<action name = "CreateBookEntry" method = "createBook" class="library.Book" >

I have added createBook() method in Book class. The application is working correctly with the default method execute().But on changing it to createBook(), I am getting the following error:

HTTP Status 500 - library.Book.createBook()

--------------------------------------------------------------------------------

type Exception report

message library.Book.createBook()

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NoSuchMethodException: library.Book.createBook()
java.lang.Class.getMethod(Unknown Source)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:546)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.37


What am I missing?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

Welcome to the JavaRanch, Titli!

There's nothing in your stacktrace that looks like a Tomcat problem, so I'm moving this thread to the Struts forum where the Struts experts hang out.


Customer surveys are for companies who didn't pay proper attention to begin with.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8914
    
    8

What does the createBook method look like? It should have the same signature as the execute method, public, String return value and no arguments.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
titli das
Greenhorn

Joined: May 05, 2013
Posts: 7
Joe Ess wrote:What does the createBook method look like? It should have the same signature as the execute method, public, String return value and no arguments.


adding my action class. I only changed execute() method name.

private String bookName;
private String author;
private int seqNo;

public static List<Book> li = new ArrayList<Book>() ;

public Book()
{
;
}

public Book(String bookname, String author, int seqNo)
{
this.bookName = bookname;
this.author = author;
this.seqNo = seqNo;
}

public String getBookName()
{
return bookName;
}
public String getAuthor()
{
return author;
}
public int getSeqNo()
{
return seqNo;
}
public void setBookName(String bookName)
{
this.bookName = bookName ;
}
public void setAuthor(String author)
{
this.author = author ;
}
public void setSeqNo(int seqNo)
{
this.seqNo = seqNo ;
}

public String createBook()
{


return "SUCCESS";

}
titli das
Greenhorn

Joined: May 05, 2013
Posts: 7
Please give me some solution
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 45
It all looks fine but still i would request you to post action class and struts.xml using code tag. If you are running from IDE make sure after changing struts.xml you restart the server because it's supposed to be redeployed.check once whether there is any spelling mistake or not in method name.
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 45
Are you implementing Action interface from struts jar.It's required because your class must have one execute method with that signature.
if don't want execute method to execute then just provide a default implementation of it. or else extend ActionSupport class from struts jar because it has default implementation of execute method.
titli das
Greenhorn

Joined: May 05, 2013
Posts: 7
Hey Ayan..I tried again with default execute() method but it didn't work. Have posted the codes. Can you suggest..
titli das
Greenhorn

Joined: May 05, 2013
Posts: 7
titli das wrote:ACTION CLASS:

package library;
import java.util.*;
import java.io.*;

public class Book {

private String bookName;
private String author;
private int seqNo;

public static List<Book> li = new ArrayList<Book>() ;

public Book()
{
;
}

public Book(String bookname, String author, int seqNo)
{
this.bookName = bookname;
this.author = author;
this.seqNo = seqNo;
}

public String getBookName()
{
return bookName;
}
public String getAuthor()
{
return author;
}
public int getSeqNo()
{
return seqNo;
}
public void setBookName(String bookName)
{
this.bookName = bookName ;
}
public void setAuthor(String author)
{
this.author = author ;
}
public void setSeqNo(int seqNo)
{
this.seqNo = seqNo ;
}

public String createBook()
{

if(bookName != null)
{
li.add(this);
}

System.out.println("Book Entry Created");
for(ListIterator<Book> it_2 = li.listIterator();it_2.hasNext();)
{
Book bookPrint = (Book)it_2.next();
System.out.println(bookPrint.getBookName() + " " + bookPrint.getAuthor() + " " + bookPrint.getSeqNo());
}

return "SUCCESS";

}

public String execute()
{



return "SUCCESS";

}

}


struts.xml:

<struts>
<constant name = "sruts.devMode" value = "true" ></constant>
<package name = "default" extends = "struts-default">

<action name = "LibraryLogin" class="library.login">
<result name = "SUCCESS">/home.jsp</result>
<result name = "FAIL">/login.jsp</result>
</action>
<action name = "CreateBookEntry" method = "createBook" class="library.Book" >
<result name = "SUCCESS">/createBookEntry.jsp</result>
</action>
<action name = "test" class="library.Book" >
<result name = "SUCCESS">/createBookEntry.jsp</result>
</action>
</package>
</struts>
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 45
I don't see any problem.Don't know why it is not working. make sure you are deploying properly.
titli das
Greenhorn

Joined: May 05, 2013
Posts: 7
Hey it got reslved..Thanks all...

The issue was with build path..Jars were added in WEB-INF folder but not in Java Resource library path
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 action method HTTP 500 error