How to take the value of a Java class variable and print to a JSP file

Asked

Viewed 417 times

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.

  • Man, how do you get this application up ?

  • 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.

  • Are you sure that the findByName method is being called?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.