Visualizzazione dei risultati da 1 a 2 su 2

Discussione: bean non riconosciuto

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    220

    bean non riconosciuto

    Ciao gente sto imparando i bean! Non mi funziona sto codice:

    bean:
    codice:
    public class Person {
    
    	private String name;
    	private String surname;
    	private int age;
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setSurname(String surname) {
    		this.surname = surname;
    	}
    
    	public String getSurname() {
    		return surname;
    	}
    
    	public void setAge(int age) {
    		this.age = age;
    	}
    
    	public int getAge() {
    		return age;
    	}
    }
    e pagine jsp:
    presentation.jsp
    codice:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    
    <form action="welcome.jsp"><input type="text" name="name">
    
    
    <input type="text" name="surname"> <input type="text" name="age">
    <input type="submit" value="Submit"></form>
    
    
    </body>
    </html>
    e welcome.jsp
    codice:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <jsp:useBean id="person" scope="session" class="Person" />
    <jsp:setProperty name="person" property="name" param="name" />
    <jsp:setProperty name="person" property="surname" param="surname" />
    <jsp:setProperty name="person" property="age" param="age" />
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    
    
    Benvenuto
    <jsp:getProperty name="person" property="name"/>
    <jsp:getProperty name="person" property="surname"/>
    
    hai
    <jsp:getProperty name="person" property="age"/>
    anni!
    </body>
    </html>
    Mi dice che l'oggetto "person" non è riconosciuto! Che devo fare?

  2. #2
    ciao!
    Mancano delle cose secondo me nella pagina welcome.jsp
    String name=request.getParameter(”name”);
    String surname= request.getParameter(”surname”);
    bean.setName(name);
    bean.setSurname(surname);

    e poi non devi memorizzare queste informazioni da qualche parte?
    di solito si usa un db oppure un file log o xml

    Guarda questo tutorial
    http://www.diplod.it/2006/12/15/tuto...tabase-access/

    Inoltre devi mettere il bean.java dentro WEB_INF/classes
    quando compili ti crea in automatico una cartella bean dentro classes che contiene bean,class

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 © 2025 vBulletin Solutions, Inc. All rights reserved.