tags:

views:

78

answers:

3
 An error occurred at line: 9 in the jsp file: /Test1.jsp
The method addURL(String, String) is undefined for the type SearchLink
6: 
7:  if(url1!=null && url1.trim().length()!=0){
8:      myfirst.SearchLink p=new myfirst.SearchLink();
9:      String result=p.addURL(url1,source1);
10:         out.println(result);
11:         System.out.println(result);
12:     }else{

Please let me know if you need any further details for answering the error cause. Thanks in advance

The complete jsp coding is as below.

<%@ page import="myfirst.*" %>
<%

String url1=request.getParameter("url");
String source1=request.getParameter("source");

if(url1!=null && url1.trim().length()!=0){
    myfirst.SearchLink p=new myfirst.SearchLink();
    String result=p.addURL(url1,source1);
    out.println(result);
    System.out.println(result);
}else{
    System.out.println("Not a valid url");
    out.println("Not a valid url");
}
%>

And this is my Java code named SearchLink and I have compiled this version too..

 package myfirst;

 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 public class SearchLink{
public static void main(String args[]) throws Exception {
    //String link="http://hosted.ap.org";
}

public String checkURL(String link,String source)throws SQLException{
    Connection con=null;
    Statement stmt=null;
    Statement stmtR=null;
    //link="http://www.topix.com/rss/city/ellensburgwa";
    //String source="Sample";
    if(con==null){
            SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
            con=SQLConnection.getNewConnection();
            stmt=con.createStatement();
            stmtR=con.createStatement();
    }
    try{
        ResultSet rs;
        boolean hasRows=false;
        rs=stmt.executeQuery("select url from urlbckup where url='"+link+"'");
        while(rs.next()){
            hasRows=true;
            //String mem=rs.getString(1);
            rs.close();
            return "This URL already exists in DB";
        }
        rs.close();
        if (!hasRows)
        {

        }
        return "This URL does not exist in DB";
    }catch(Exception e){
        e.printStackTrace();
        return e.getMessage();
    }finally{
        if(stmtR!=null){
            stmtR.close();
        }
        if(stmt!=null){
            stmt.close();
        }
        if(con!= null){
            con.close();
        }
    }
}


public String addURL(String link,String source)throws SQLException{
        Connection con=null;
        Statement stmt=null;
        Statement stmtR=null;
        if(con==null){
                SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
                con=SQLConnection.getNewConnection();
                stmt=con.createStatement();
                stmtR=con.createStatement();
    }
        try{
            PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urlbckup VALUES(?, ?, ?, ?, ?)");
            insertUrlStatement.setInt(1, 21211);
            insertUrlStatement.setString(2, link);
            insertUrlStatement.setString(3, source);
            insertUrlStatement.setInt(4, 1);
            insertUrlStatement.setInt(5, 0);
            insertUrlStatement.executeUpdate();
            insertUrlStatement.close();
            return "The URL has been added to the Database";}
        catch(Exception e){
            e.printStackTrace();
            return e.getMessage();
        }finally{
            if(stmtR!=null){
                stmtR.close();
            }
            if(stmt!=null){
                stmt.close();
            }
            if(con!= null){
                con.close();
            }
    }


}

}

+1  A: 

it means that the SearchLink class doesn't have a method with the signature addURL(String, String).

Jeroen Rosenberg
+3  A: 

You should redeploy your application.

In most IDEs, when you deploy web applications jsp pages can still be edited and "redeployed" on the fly onto the web container. But with classes, you need to recompile your code and redeploy your application.

Now some IDE and auto redeploy your application on save. And there are projects like jrebel which allow you to change classes into your application without redeploying it.

Colin Hebert
How many times has my code been perfect, and the server gives me errors about code that was fixed and I did not remember fixing it... Too many.
Kieveli
Tomcat had to be restarted.. now its working fine... thanks guys..
LGAP
+2  A: 

Assuming that myfirst.SearchLink is a fully qualified class name, the compiler is telling you that the SearchLink class does not define a method called addURL that takes two String arguments.

Possible causes:

  • you have misspelled the name of the method
  • you have forgotten to declare the method
  • you have declared the method with arguments with the wrong types
  • you have called the method with arguments of the wrong types.

EDIT

None of the above seem to apply, so my next guess is that you have neglected to compile and deploy the latest version of the SearchLink class to your web server.

Stephen C