PDA

View Full Version : problemi con javabean


carMAN
14-09-2004, 22:35
sono alle prime armi con i javabean, ma subito sono insorti i primi problemi. Iniziamo dal principio.
Ho compilato il seguente javabean:


import java.io.Serializable;
public class Counter implements Serializable {
int count=0;
public Counter() {}
public int getCount(){count++; return count;}
public void setCount(int count){this.count=count;}
}


nella cartella ROOT di tomcat ho creato la cartella testjsp ed in essa le cartelle innestate WEB-INF e classes. In classes ho inserito il file compilato Counter.class
Ricapitolando:
ROOT\testjsp\WEB-INF\classes\Counter.class
Successivamente ho creato il file jsp:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="counter" scope="page" class="Counter" />

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Esempio di bean con ambito page</title>
</head>

<body>
<h3>Esempio di bean con ambito page</h3>
<center><b>Il valore count corrente per il bean counter è : </b>
<%=counter.getCount()%></center>
</body>
</html>


Ho inserito tale file in ROOT\testjsp

Ho avviato tomcat e ho ottenuto il seguente errore:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /testJSP/page_counter.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat4\work\Standalone\localhost\_\testJSP\page_counter_jsp.java:44: cannot resolve symbol
symbol : class Counter
location: class org.apache.jsp.page_counter_jsp
Counter counter = null;
^
....

Chi mi aiuta, per favore...

carMAN
15-09-2004, 16:39
nessuno mi sa aiutare?
ciao ciao

Zeus84
15-09-2004, 16:43
Sto dando un occhiata ma mi sembra tutto ok...:muro: :muro:

kingv
15-09-2004, 16:59
Originariamente inviato da Zeus84
Sto dando un occhiata ma mi sembra tutto ok...:muro: :muro:



anche a me sembra tutto giusto, non capisco :confused:

Zeus84
15-09-2004, 17:05
Originariamente inviato da kingv
anche a me sembra tutto giusto, non capisco :confused:

ti posto una mia esperienza che mi ha lasciato sconvolto...non voglio criticare ma il TomCat secondo me ha alcora qualche bug di troppo...

Tempo fa avevo creato anch'io un JavaBean...tutto corretto solo che ricevevo lo stesso errore di sopra...
non riuscivo a capire e alla fine ho risolto solamente cambiando il percorso di tutto il mio sito...
per dire prima la cartella era Root\nome1, poi Root\nome2...

carMAN
15-09-2004, 17:25
purtroppo non ho risolto nulla.
Ho sostituito la cartella "testjsp" con "bean" ma non è cambiato nulla.
ciao ciao

Zeus84
16-09-2004, 11:30
x carMAN: la bustto lì ma non so se risolvi...avevo letto in giro che il javabeans devono avere metodi getXXX e setXXX per ogni campo d'istanza dove XXX è il nome del campo...
tu nel bean hai usato proprietà count e metodi con Count...prova a scrivere getcount e setcount..
fammi sapere

carMAN
16-09-2004, 21:30
nulla!!!!
ma nessuno riesce ad aiutarmi!!!!

ciao ciao e grazie :muro: :muro: :muro:

Zeus84
17-09-2004, 01:16
Originariamente inviato da carMAN
nulla!!!!
ma nessuno riesce ad aiutarmi!!!!

ciao ciao e grazie :muro: :muro: :muro:

ma non so più cosa pensare..domani se ho un pò di tempo copio il codice e vedo cosa riesco a fare...
per ora non ho il tomcat installato

carMAN
21-09-2004, 11:37
ma vi siete scordati di me? :cry: :cry: :cry: :cry:

miondere
19-10-2004, 19:41
Sto iniziando ora a guardare per la prima volta i java bean. Ho provato a
far girare un piccolo esempio che ho trovato in rete, ma non ne vuole sapere
di partire, mi da errore. Sembra il solito che avete postato qui in questo thread

Utilizzo tomcat, metto il file .class in webapps\ROOT\WEB-INF\classes.
Devo inserire qualche libreria particolare per i bean?
Sotto ho messo il codice e l'errore che ottengo.
Grazie mille a chiunque mi aiuterà, ciao




----------------------------------------

<html>
<head><title>Utilizzo del Bean</title></head>
<body>
<jsp:useBean id="utente" scope="session" class="InfoUtente"/>
<jsp:setProperty name="utente" property="nome" value="Zina&Tram"/>
<%
utente.setNome("Zina&Tram");
utente.setEmail("[email protected]");
%>
<jsp:getProperty name="utente" property="nome"/>
<% out.println(utente.getNome());
out.println(utente.riassunto()); %>
<% utente.aggiornaPV();
out.println(utente.getPagineViste()); %>
</html>

---------------------------------

public class InfoUtente {
private String nome = null;
private String email = null;
private int pagineViste;

public InfoUtente() {
pagineViste=0;
}


public void aggiornaPV() {
pagineViste++;
}

public int getPagineViste(){
return pagineViste;
}

public void setNome(String value) {
nome = value;
}

public String getNome() {
return nome;
}

public void setEmail(String value) {
email = value;
}

public String getEmail() {
return email;
}

public String riassunto(){
String riassunto = null;
riassunto = "Il nome dell'utente è"+nome+",";
riassunto+= "il suo indirizzo e-mail è: "+email;
riassunto+=" e ha visitato "+pagineViste+" del sito";
return riassunto;
}

}

-------------------------





type Exception report

message

description The server encountered an internal error () that prevented it
from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /InfoUtente.jsp
Generated servlet error:
C:\Programmi\Tomcat\jakarta-tomcat-5.0.27\work\Catalina\localhost\_\org\apac
he\jsp\InfoUtente_jsp.java:45: cannot resolve symbol
symbol : class InfoUtente
location: class org.apache.jsp.InfoUtente_jsp
InfoUtente utente = null;
^


An error occurred at line: 4 in the jsp file: /InfoUtente.jsp
Generated servlet error:
C:\Programmi\Tomcat\jakarta-tomcat-5.0.27\work\Catalina\localhost\_\org\apac
he\jsp\InfoUtente_jsp.java:47: cannot resolve symbol
symbol : class InfoUtente
location: class org.apache.jsp.InfoUtente_jsp
utente = (InfoUtente) _jspx_page_context.getAttribute("utente",
PageContext.SESSION_SCOPE);
^


An error occurred at line: 4 in the jsp file: /InfoUtente.jsp
Generated servlet error:
C:\Programmi\Tomcat\jakarta-tomcat-5.0.27\work\Catalina\localhost\_\org\apac
he\jsp\InfoUtente_jsp.java:49: cannot resolve symbol
symbol : class InfoUtente
location: class org.apache.jsp.InfoUtente_jsp
utente = new InfoUtente();
^


An error occurred at line: 10 in the jsp file: /InfoUtente.jsp
Generated servlet error:
C:\Programmi\Tomcat\jakarta-tomcat-5.0.27\work\Catalina\localhost\_\org\apac
he\jsp\InfoUtente_jsp.java:64: cannot resolve symbol
symbol : class InfoUtente
location: class org.apache.jsp.InfoUtente_jsp

out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((InfoUtente
)_jspx_page_context.findAttribute("utente")).getNome())));
^
4 errors




org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandle
r.java:84)

org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:3
32)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:5
11)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
95)
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:802)