How a text input box in a jsp page can receive the value of an sql query

Asked

Viewed 18 times

0

I want to send the result of a SELECT COUNT(*) FROM tabela for an input text box on the jsp page: On the page dao I have:


public int getRowNumber() throws SQLException {
        
        int numberRow = 0;
        String sql = "SELECT COUNT(*) FROM usuario";        
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultset = preparedStatement.executeQuery();
                    
        while(resultset.next()){
            numberRow = resultset.getInt("count(*)");
        }           
        return numberRow;
    }

In Servlet I did:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().append("Served at: ").append(request.getContextPath());
    
        RequestDispatcher view = request.getRequestDispatcher("cadastroUsuario.jsp");
        try {
            request.setAttribute("usuarios", daoUsuario.getRowNumber());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        view.forward(request, response);        
    
    }


On the jsp page I’m lost:

<%= ??? %>
No answers

Browser other questions tagged

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