teelou teelou -4 years ago 101
Java Question

Java and JSP - java.lang.NoSuchMethodError?

How can I set property and get it on a jsp page?

my Hello.class,

package Foo;

public class Hello
{
private String message;

public String sayHello ()
{
return "Hello World!";
}

public String getMessage() {
return this.message;
}

public void setMessage(String x) {
this.message = x;
}
}


My index.jsp,

<html>
<head>
<title>Custom Class</title>
</head>
<body>

<%@ page import="Foo.Hello" %>

<%
Hello hello = new Hello();

hello.setMessage("Hello There!");
out.print(hello.getMessage());
out.print(hello.sayHello());
%>

</body>
</html>


Error,

org.apache.jasper.JasperException: An exception occurred processing JSP page /custom-class/index.jsp at line 12

9: <%
10: Hello hello = new Hello();
11:
12: hello.setMessage("Hello There!");
13: out.print(hello.getMessage());
14: out.print(hello.sayHello());
15: %>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: java.lang.NoSuchMethodError: Foo.Hello.setMessage(Ljava/lang/String;)V
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:908)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:837)
org.apache.jsp.custom_002dclass.index_jsp._jspService(index_jsp.java:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NoSuchMethodError: Foo.Hello.setMessage(Ljava/lang/String;)V
org.apache.jsp.custom_002dclass.index_jsp._jspService(index_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


I'm new to Java and JSP. What have done incorrectly?

Answer Source

I don't find any problem in your code it is working fine i think you have to clean your project and redeploy it on your server and also clean and restart your server then it will surely work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download