java - JSP 编译失败,返回 "The method [MethodSignature] is undefined for the type [ClassName]"

标签 java jsp

 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代码如下。

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


}

最佳答案

您应该重新部署您的应用程序。

在大多数 IDE 中,当您部署 Web 应用程序时,仍然可以编辑 jsp 页面并将其动态“重新部署”到 Web 容器中。但是对于类,您需要重新编译代码并重新部署应用程序。

现在有些 IDE 会在保存时自动重新部署您的应用程序。还有像jrebel这样的项目这允许您将类更改为您的应用程序而无需重新部署它。

关于java - JSP 编译失败,返回 "The method [MethodSignature] is undefined for the type [ClassName]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3566574/

相关文章:

java - 如何区分音频文件和视频文件?

java - JSP 中字符串变量中的单引号转义

javascript - 使用 Jquery 在新打开的浏览器窗口上触发元素单击

javascript - 无法从 Kendo Window 中的内容关闭窗口

java - TextView中的重复文本对Button的压力

java - MongoDB Java 简单示例失败

hibernate - Spring MVC - Hibernate form :errors and bindingresult, jsp 不显示错误消息

java - 如何在下载过程中更改文件名

java - C# 和 Java 将 DateTime 转换为字节数组时的区别

java - 登录多线程应用程序