0
I am trying to transfer the value of a query counter in the database to a class variable, to call it in a JSP file, it will display it in an HTML page. The problem is that when I call the variable in JSP it prints the initialization value of the variable, in this case 13. HELP ME PLEASE!!!!!!
package novomongoteste;
import com.mongodb.DBObject;
import com.mongodb.QueryBuilder;
import java.util.List;
import java.util.regex.Pattern;
import static novomongoteste.ContatoTeste.b;
public class ContatoTeste {
private IContatoDao<Contato> dao = new ContatoDao();
public static int a = 13 // DECLARAÇÃO DA VARIAVEL DE CLASSE
public static void main(String[] args) {
ContatoTeste t = new ContatoTeste();
t.findByName();
}
private void findByName() {
DBObject query = QueryBuilder
.start("uf")
.regex(Pattern.compile("PB"))
.get();
List<Contato> contatos = dao.findContatos(query);
int contador = 0;
for (Contato contato : contatos) {
contador += 1;
System.out.println(contato.toString());
}
System.out.println(contador);
a = contador; // ALOCAÇÃO DO VALOR DO CONTADOR PARA A VARIAVEL D CLASSE
}
}
********************************* JSP CODE **************************
<%
out.println(ContatoTeste.a);
%>
Remove the commented code from the question, it can help in readability and then we can help you with faster, and put your JSP code.
– Isaías de Lima Coelho
Man, how do you get this application up ?
– Isaías de Lima Coelho
Using Netbeans, I used a function of my own to create a web application, the problem is that the class variable being referenced in JSP is only recognized with the global value and not with the value of the account. When I run the HTML file in Netbeans it opens a page in the browser with a button, to print the number.
– Daniel Ferreira
Are you sure that the findByName method is being called?
– Isaías de Lima Coelho