Boa noite,
O javaBean do JSP só permite com gettters e setters aceitam métodos diferentes?
Como consigo retornar no jsp o resultado deste método calcular(int numero) ?
package bean;
public class BeanCursoJsp {
private String nome;
private String ano;
private String sexo;
private int numero;
public int calcular() {
return this.numero *100;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getAno() {
return ano;
}
public void setAno(String ano) {
this.ano = ano;
}
public String getSexo() {
return sexo;
}
public void setSexo(String sexo) {
this.sexo = sexo;
}
public int getNumero() {
return numero;
}
public void setNumero(int numero) {
this.numero = numero;
}
}
index.jsp
<jsp:useBean id="calcula" class="bean.BeanCursoJsp" type="bean.BeanCursoJsp" scope="page"/>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>beans jsp</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body >
<form action="cabecalho2.jsp" method="post" >
<br/>
Nome:<br/>
<input type="text" id="nome" name="nome"/>
<br/>
Ano:<br/>
<input type="text" id="ano" name="ano" />
<br/>
Sexo:<br/>
<input type="text" id="sexo" name="sexo" />
<br/>
Calcula:<br/>
<input type="text" id="numero" name="calcula" />
<br/>
<input type="submit" value="testar" />
<br/>
</form>
</body >
</html>
saida.jsp
<jsp:useBean id="calcula" class="bean.BeanCursoJsp" type="bean.BeanCursoJsp" scope="page"/>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>beans jsp</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<html>
<body>
<jsp:setProperty property="*" name="calcula"/>
<h2>cabecalho </h2>
<br/>
<br/>
<br/>
<jsp:getProperty property="nome" name="calcula"/>
<br/>
<jsp:getProperty property="ano" name="calcula"/>
<br/>
<jsp:getProperty property="sexo" name="calcula"/>
<br/>
<jsp:getProperty property="numero" name="calcula"/>
<jsp:getProperty property="calcular" name="calcula"/>
</body>
</html>