Take the 2-minute tour ×

I want to generate a SQL query when I press the submit button and show the number of rows it returns without refreshing. I've manage to do this below, but it refreshes and clears everything and the value is always 0. I'm using Tomcat and NetBeans.

  • I'm using the submit function because after I solve this I will return false if something happens.

  • The msg span is where the rows returned are going to be displayed.

  • Funciones.setSql generates the SQL using the value on the option selected and stores in a static String. Then the Funciones.count() just makes the query and stores the number of rows in a variable called numF.

  • Funciones.lista() generates all the data in the database using one specific field and setting a value (id).


<div data-role="page" id="realizadas">
    <%@include file="header.jsp"%>
    <div data-role="content">
        <form name="tareasr" id="tareasr" data-mini="true" method="post">
            <fieldset data-mini="true" data-role="controlgroup" data-type="horizontal"> 
                <select data-inline="true" name="vina" id="vina">
                    <option value="0">VIÑAS</option>
            <input data-icon="search" type="submit"  value="Buscar" />
        <b><span id="msg"></span></b>


            $("#tareasr").submit(function() {
            <jsp:useBean id="formHandler" class="ges.FormBean">
                <jsp:setProperty name="formHandler" property="*"/>
                var men="Num: ";
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You're mixing Java code and JavaScript code as if they were the same thing. Java code inside a JSP should be avoided, and if it's there, it must be inside scriptlet tags (<% ... %>). Thsi Java code is executed at server-side, when the JSP is executed and the HTML and JavaScript code is generated.

Then, in the browser, JavaScript code can be executed. This JavaScript code can't invoke methods of Java objects which were used to generate HTML at server-side. Java doesn't exist in the browser. If you need to invoke server-side Java code from the browser, you must send a new HTTP request to the server (by clicking a link, submitting a form, or sending an AJAX request).

share|improve this answer
I've edited what was wrong. So i need to post it. using request.getparameter() It stills gives me null and the web is refreshed –  Dantalian Jun 30 '12 at 10:42
I solved it with ajax –  Dantalian Jul 2 '12 at 13:51

Your Answer


