Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 action method HTTP 500 error

 
titli das
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9302
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the createBook method look like? It should have the same signature as the execute method, public, String return value and no arguments.
 
titli das
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please give me some solution
 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ayan..I tried again with default execute() method but it didn't work. Have posted the codes. Can you suggest..
 
titli das
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any problem.Don't know why it is not working. make sure you are deploying properly.
 
titli das
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic