Ciao gente sto imparando i bean! Non mi funziona sto codice:
bean:
e pagine jsp: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; } }
presentation.jsp
e welcome.jspcodice:<%@ 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>
Mi dice che l'oggetto "person" non è riconosciuto! Che devo fare?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>

Rispondi quotando