Reputation: 689
I know this question has been asked a lot of times, but so far, none of the answers previously given have worked for me, here is my code:
<html>
<head>
<title>Programa</title>
</head>
<body>
<div>
Introduzca una palabra a buscar:
<input type="text" id="INPUT">
<%@ page import="java.net.URL" %>
<%@ page import="com.google.gson.*" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.Reader" %>
<%@ page import="javax.swing.*" %>
<%@ page import="java.awt.event.*;" %>
<%!
int min(int a,int b) {
return (a>b)? b:a;
}
int edit_distance(String a,String b) {
int n = a.length(), m = b.length(),costo;
int[][] mat = new int[n+1][m+1];
for(int i=0;i<=n;++i) mat[i][0] = i;
for(int j=0;j<=m;++j) mat[0][j] = j;
for(int i=1;i<=n;++i) {
for(int j=1;j<=m;++j) {
costo = a.charAt(i-1) == b.charAt(j-1)? 1 : 0;
mat[i][j] = min(min(mat[i-1][j] + 1,mat[i-1][j-1] + costo),mat[i][j-1] + 1);
}
}
return mat[n][m];
}
String resultados_de_la_busqueda(String search) { //Básicamente lo que hace esta función es devolverte una cadena con los resultados de la búsqueda
StringBuffer RES = new StringBuffer("<html>");
String google = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="; //El enlace para buscar en google
String charset = "UTF-8";
URL url;
Reader reader;
try {
url = new URL(google + URLEncoder.encode(search, charset));
try {
reader = new InputStreamReader(url.openStream(), charset);
GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);
for(int i=0;i<3;++i) {
RES.append(results.getResponseData().getResults().get(i).getTitle());
RES.append("<br/>");
RES.append("<a href=\"");
RES.append(results.getResponseData().getResults().get(i).getUrl());
RES.append("\">" + results.getResponseData().getResults().get(i).getUrl() + "</a>");
RES.append("<br/><br/>");
}
} catch(Exception e) {}
} catch(Exception e) {}
return RES.toString();
}
%>
<%
//Se supone que acá debo mostrar el resultado de la búsqueda...
out.println(resultados_de_la_busqueda("taringa"));
%>
</div>
</body>
</html>
And here is the error I'm getting:
org.apache.jasper.JasperException: No se puede compilar la clase para JSP:
Ha tenido lugar un error en la línea: 47 en el archivo jsp: /Programa.jsp
GoogleResults cannot be resolved to a type
Gson cannot be resolved to a type
Any idea on what is causing the problem?
Edit 1:
This is the GoogleResults class:
import java.util.List;
public class GoogleResults {
private ResponseData responseData;
public ResponseData getResponseData() { return responseData; }
public void setResponseData(ResponseData responseData) { this.responseData = responseData; }
public String toString() { return "ResponseData[" + responseData + "]"; }
static class ResponseData {
private List<Result> results;
public List<Result> getResults() { return results; }
public void setResults(List<Result> results) { this.results = results; }
public String toString() { return "Results[" + results + "]"; }
}
static class Result {
private String url;
private String title;
public String getUrl() { return url; }
public String getTitle() { return title; }
public void setUrl(String url) { this.url = url; }
public void setTitle(String title) { this.title = title; }
public String toString() { return "Result[url:" + url +",title:" + title + "]"; }
}
}
Upvotes: 3
Views: 16045
Reputation: 126
This Happen to me after my java was automatically updated. Check The JRE is correctly set: RClick on the project , choose Build Path ->configure Build Path , Go to libraries Path and make sure JRE System library is properly configured.
Upvotes: 1
Reputation: 93
Sometimes if you are importing your project into a new workspace, this problem is encountered if JRE was different of the previous workspace frm the new workspace, try changing the jre system library in build path. It works out
Upvotes: 1
Reputation: 618
Create new project. Copy all files in this new project from old project. Delete old one and rename new project.
Thats it. It will work fine
Upvotes: 0
Reputation: 2840
Make sure your GoogleResults.class is being compiled under WEB-INF/classes/
Also it seems to me like you should import this file at the beginning of your .jsp.
Hope this help
Upvotes: 0
Reputation: 442
Seems like its not picking up your class...
Do a Project>Clean and then Refresh it (F5).
Hoped this helped, here is where I got it from:
Upvotes: 7