PDA

View Full Version : [JSP] Il mio primo Bean.. non va


TorpedoBlu
02-02-2008, 17:10
ciao, sto provando a scrivere il mio primo bean Usando Eclipse:

Nuovo progetto Web Dinamico -> nuova classe:





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

}//InfoUtente





poi nuova JSP ->


<html>
<head><title>Utilizzo del Bean</title></head>
<body>
<jsp:useBean id="utente" scope="session" class="InfoUtente"/>
</body>
</html>



e gia mi da un Warning: "The local variable Utente is never Read"

mi dico: va beh vediamo lo stesso:

RunAs ->on Server ->mi fa selezionare Tomcat 6 regolarmente installato
Si avvia Tomcat e mi da errore:

HTTP Status 500 -



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: /index.jsp
InfoUtente cannot be resolved to a type




:help:

isAlreadyInUse
02-02-2008, 17:18
Ma la classe è in pakage?

TorpedoBlu
02-02-2008, 17:40
Ma la classe è in pakage?


la classe anche se sconsigliato non è in un package, ho fatto semplicementa "aggiungi classe" e mi ha messo il file java nel default package e me lo ha regolarmente compilato nella build /classes

il fatto è che... il file web.xml dovrebbe contenere qualche info? eclipse fa tutto da se?

è così
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>primoWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

isAlreadyInUse
02-02-2008, 17:58
Nel'xm nn deve esservi niente metti il bean in un pakage e riporva

<jsp:useBean id="utente" scope="session" class="net.codersforum.samples.InfoUtente"/>

TorpedoBlu
02-02-2008, 20:51
Nel'xm nn deve esservi niente metti il bean in un pakage e riporva

<jsp:useBean id="utente" scope="session" class="net.codersforum.samples.InfoUtente"/>

gia, il bean deve stare in un package per forza. ora funziona. :)