Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    132

    [JSP] Problema con i Bean

    Salve, mi sto cimentando con Jsp, sono niubbo, ed ho un problema.
    Se provo ad usare un bean, non riesco ad utilizzare il get sui bean. Mi da errore sempre e cmq. Io ho fatto 2 paginette, in 1 leggo dei dati tramite 1 form, li metto in 1 bean, e poi vorrei farli stampare da 1 altra pagina. La sintassi che uso con i bean è la seguente:

    <jsp:useBean id="miobean"
    scope="request"
    class="beans.Person">
    <jsp:setProperty name="miobean" property="*" />
    </jsp:useBean>

    Se metto il get, e cioè:
    <jsp:getProperty name = "miobean" property = "nome" />
    il net beans mi da errore sempre e cmq, e pure sulla carta tutto è perfetto. Il bean è fatto bene (infatti il set funziona) il bean si trova nella giusta cartella, ma allora dove sbaglio????
    Ecco l'errore che ho:

    visualizzabean.jsp [-1:-1] Cannot find any information on property 'nome' in a bean of type 'beans.Person'
    Errors compiling visualizzabean.


    X favore, è da oggi alle 15 che sto bestemmiando, aiutatemi...grazie

  2. #2
    posta il codice del bean e quello della pagina che fa il set...

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    132
    Ecco:
    il bean

    package beans;

    import java.io.*;
    import java.util.*;

    public class Person implements Serializable
    {
    private String nome;
    private String cognome;
    private String username;
    private String password;
    private String email;

    public String getNome()
    {
    return nome;
    }

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

    public String getCognome()
    {
    return cognome;
    }

    public void setCognome(String s)
    {
    cognome = s;
    }

    public String getUsername()
    {
    return username;
    }

    public void setUsername(String s)
    {
    username = s;
    }


    public String getPassword()
    {
    return password;
    }

    public void setPassword(String s)
    {
    password = s;
    }

    public boolean NameValid() {
    boolean isValid = false;
    if (nome != null) {
    isValid = true;
    }
    return isValid;
    }

    }


    La pagina con il form

    <%@page contentType="text/html"%>
    <%@ page language="java" %>
    <html>
    <head><title>Registrazione</title></head>
    <body>

    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>

    <jsp:useBean id="miobean" class="beans.Person" scope="session" />
    <h1>Inserisci i tuoi dati</h1>


    <%--<jsp:getProperty name="bean" property="nome" />--%>
    <form action="visualizzabean.jsp" method="post" >
    <table>
    <td>Nome</td>
    <td> <input type="text" name="nome"></td>
    <tr>
    <td>Cognome</td>
    <td> <input type="text" name="cognome"></td>
    </tr>
    <tr>
    <td>Username</td>
    <td> <input type="text" name="username"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input type="password" name="password"></td>
    </tr>
    <tr>
    <td>E-Mail</td>
    <td><input type="text" name="email"></td>
    </tr>
    <tr>
    <td>Tipo di utilizzo</td>
    <td>
    <input type="radio" name="tipo" value='privato' checked>privato

    <input type="radio" name="tipo" value='azienda' >azienda
    </td>
    </tr>

    <%--<jsp:setProperty name="miobean" property="nome" value="m" />--%>



    <td>
    <input type="submit" value="INVIA" onsubmit="visualizzabean.jsp">
    </td>
    </body>
    </html>

    la pagina con il get

    <%@page contentType="text/html"%>
    <html>
    <head><title>JSP Page</title></head>
    <body>
    <jsp:useBean id="miobean"
    scope="request"
    class="beans.Person">
    <jsp:setProperty name="miobean" property="*" />
    </jsp:useBean>
    <%--<%=bean.getNome()%>--%>
    <jsp:getProperty name = "miobean" property = "nome" />
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>

    </body>
    </html>

    Fammi sapere, io non ne riesco a venire a capo.
    Grazie!!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.