Help me to solve this Jsp problem

10-11  Source: Network gathering  Views:0 

Advertisement
//Class1.java
package p1.p2;
public class Class1 implements Serializable
private String name1,name2;
public void setName1(String name)
name1=name;
public String getName1()
return name1;
public void setName2(String name)
name2=name;
public String getName2()
return name2;
//Class2.java
package p1.p2;
public class Class2
String name1,name2;
public String insert(Class1 c1)
name1 = c1.getName();
name2 = c2.getName();
return name1;
//Class3.jsp
<%@ page import="p1.p2.*" %>
<html>
<form action="/bobby/Class3.jsp" method=post>
Name1 : <input type=text name="cn1">
Name2 : <input type=text name="cn2">
<input type=submit value="Click"/>
</form>
</html>
<%! String a,b,c; %>
<%
Class1 c1 = new Class1();
Class1 c2 = new Class2();
a=request.getParameter("cn1");
b=request.getParameter("cn2");
c1.setName(a);
c1.setName(b);
c=c2.insert(c1);
out.println(c);
%>
WHEN I RUN THE JSP PROGRAM I GOT THE FOLLOWING ERROR.TELL ME THE SOLUTION TO SOLVE THIS PROBLEM.
javax.servlet.ServletException:
p1.p2.Class2.insert(Lp1/p2/Class1;)Ljava/lang/String;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl .java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.j ava:758)
org.apache.jsp.Class3_jsp._jspService(Class3_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
root cause
java.lang.NoSuchMethodError: p1.p2.Class2.insert(Lp1/p2/Class1;)Ljava/lang/String;
org.apache.jsp.Class3_jsp._jspService(Class3_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
First, please put your code inside code tags. There's a nice little button. All you have to do is paste your code, highlight it and press the little code button. Thanks.
I had to make some adjustments to your original post. Either you had some closing braces in the wrong place, or you hve no idea what you're doing. I'm going to assume that Class1 is in a file named p1/p2/Class1.java and Class2 is in p1/p2/Class2.java.
//Class1.java
package p1.p2;
public class Class1 implements Serializable
    private String name1,name2;
    public void setName1(String name)
        name1=name;
    public String getName1()
        return name1;
    public void setName2(String name)
        name2=name;
    public String getName2()
        return name2;
//Class2.java
package p1.p2;
public class Class2
    String name1,name2;
    public String insert(Class1 c1)
        name1 = c1.getName();
        name2 = c2.getName();
        return name1;
//Class3.jsp
<%@ page import="p1.p2.*" %>
<html>
<form action="/bobby/Class3.jsp" method=post>
Name1 : <input type=text name="cn1">
Name2 : <input type=text name="cn2">
<input type=submit value="Click"/>
</form>
</html>
<%! String a,b,c; %>
<%
    Class1 c1 = new Class1();
    Class1 c2 = new Class2(); //<-- problem here, do you see it?
    a=request.getParameter("cn1");
    b=request.getParameter("cn2");
    c1.setName(a);
    c1.setName(b);
    c=c2.insert(c1);
    out.println(c);
%>Note the I highlighted the problem above. HTH.
Related articles