2010-08-25 69 views
1
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{ 

請讓我知道您是否需要任何有關回答錯誤原因的更多詳細信息。 在此先感謝JSP編譯失敗,並且「方法[MethodSignature]未定義爲[ClassName]類型」

完整的jsp編碼如下。

<%@ 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"); 
} 
%> 

這是我命名SearchLink Java代碼,我編這個版本太..

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(); 
      } 
    } 


} 

}

+0

問題是'myfirst.SearchLink'沒有定義'addURL(String,String)'方法。你要麼拼寫錯誤,要麼不存在。 – Nubsis 2010-08-25 14:00:13

+0

您可以向我們展示'SearchLink'類,因爲錯誤在於? – Riduidel 2010-08-25 14:00:43

+0

我更新了代碼....請指教.. – LGAP 2010-08-25 14:02:04

回答

6

您應該重新部署您的應用程序。

在大多數IDE中,當您部署Web應用程序時,jsp頁面仍然可以在Web容器上進行編輯和「重新部署」。但是對於類,您需要重新編譯代碼並重新部署應用程序。

現在一些IDE和自動重新部署您的應用程序保存。還有像jrebel這樣的項目,它們允許您在不重新部署的情況下將類更改爲您的應用程序。

+0

我的代碼完美無瑕,服務器給我錯誤的代碼已修復,我不記得修復它...太多了。 – Kieveli 2010-08-25 14:10:30

+0

Tomcat必須重新啓動..現在它的工作正常......感謝傢伙.. – LGAP 2010-08-25 17:37:57

+0

我只是半小時迷惑了爲什麼我在Eclipse中編輯JSP時出錯,並添加了類StringBuffer或StringBuilder導致了同樣的錯誤(更精確地說,使用它們的構造函數)。包java.lang中的所有類都應該被自動導入。最後,我意識到Tomcat還在運行,所以按下紅色方塊停止它,然後從菜單中選擇Project - > Clean ...,錯誤消失。 – 2012-02-25 01:17:43

1

這意味着SearchLink類沒有一種方法與簽名addURL(String,String)。

2

假設myfirst.SearchLink是一個完全合格的類名,編譯器告訴您SearchLink類沒有定義一個名爲addURL方法採用兩個String參數。

可能的原因:

  • 你有拼寫錯誤的方法
  • 你忘了申報
  • 您已聲明的方法,該方法與參數與錯誤類型的名稱
  • 你有稱爲具有錯誤類型參數的方法。

編輯

以上都不似乎適用,所以我的下一個猜測是,你忽視了編譯和部署最新版本的SearchLink類到Web服務器。

相關問題