0

I am calling java method in jsp page that is showing servlet.service exception nosuch method exception or class

<%@page import="java.util.ArrayList"%>
<%@page import="Model.Validation"%>
<%
String username=request.getParameter("uname");
String password=request.getParameter("password");
System.out.print(username+"\nhellloo\n"+password+"\n re\n");
ArrayList<String> names=Validation.validateuname(username,password);
String name=(String)names.get(0);
String role=(String)names.get(1);
 if(role.equals("Administrator"))
 {
out.print("{success:true,errors:{reason:'Administrator'},uname:{name:'"+name+"'}}");

}else if(role.equals("User"))
 {
out.print("{success:true,errors:{reason:'User'}}");

}else
 {
 out.print("{success:false,errors:{reason:'User name or Password is wrong, please try              again'}}");

  }

%>

SEVERE: Servlet.service() for servlet jsp threw exception java.lang.NoSuchMethodError: Model.Validation.validateuname(Ljava/lang/String;Ljava/lang/String;)Ljava/util/ArrayList; at org.apache.jsp.check_005flogin_jsp._jspService(check_005flogin_jsp.java:61) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)

Vikdor
  • 23,934
  • 10
  • 61
  • 84
Yarram Reddy
  • 25
  • 1
  • 10

3 Answers3

1

The StackTrace is telling you that there is no method

public class Validation {
    public static ArrayList<String> validateuname(String, String) {
        ArrayList<String> ls = new ArrayList<String>();
        //a nice implementation goes here!
        return ls; 
    }
}

Check if this is a valid method. If your method is right, then recompile your code and deploy your web application again.


There is a major problem in your code, you must not use scriptlets (the Java code inside the <% ... %> inside your jsps). There is a further explanation about the problems and solutions for this:

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
0

the exception is being throw here on this line

ArrayList<String> names=Validation.validateuname(username,password);

is Validation a reference ?, if it is a reference to an object check your validatename()method in that class. from your code i can say its not a reference you are trying to call valudatename() with the class name. try this:

  ArrayList<String> names=new Validation().validateuname(username,password);
PermGenError
  • 45,977
  • 8
  • 87
  • 106
0
  1. Make sure that your method validateuname exists in your Validation class.

  2. Make sure that you have compiled the class, saved it to proper project directory in your server (Seems that you are using Tomcat), and that you have restarted the server. Note that in every new method declaration, you need to restart your server.

Russell Gutierrez
  • 1,372
  • 8
  • 19