Need to see the invoking JSP .. (in the case you might have something like..) <form.. action = "goToThisServlet"> and then later on the submit or onClick onSubmit="goToThisServlet" ???? Martin -- ********************************************************************* This email message and any files transmitted with it contain confidential information intended only for the person(s) to whom this email message is addressed. If you have received this email message in error, please notify the sender immediately by telephone or email and destroy the original message without making a copy. Thank you.
----- Original Message ----- From: <[EMAIL PROTECTED]> To: <users@tomcat.apache.org> Sent: Friday, June 30, 2006 2:45 PM Subject: problem with doPost method - executed twice Dear all, I have developed a web application that is running under tomcat 5.5.17 that is under windows XP. I have a servlet that retrieves data from a html form, creates an object and passes this object to a manager class that inserts the data into Oracle. Everything works fine except that I noticed that my doPost method executes twice each command. It is incrementing twice the Oracle sequence and inserting twice the same record. Does anyone have a clue on what is going on? When I look into the table this is what I get: SQL> select * from marcapropriedade; IDMARCAPROPRIEDADE DESCRICAO ------------------ ------------------------------ 1 Acordos Internacionais 2 Adm Pública Federal 3 Defesa 4 Mercosul 45 lalalala 46 lalalala 47 papapapapapa 48 papapapapapa 49 another test 50 another test 10 linhas selecionadas. ============================================================================ ================ This is my servlet: //package servlets; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import objeto.MarcaPropriedade; import objeto.MarcaPropriedadeGestor; public class RegistraMarcaPropriedade extends HttpServlet { /** * Process the HTTP Post request */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("I am here 1"); // Create object to store information from previous form MarcaPropriedade marcaPropriedade = new MarcaPropriedade(); marcaPropriedade.setDescricao(request.getParameter("txtDescricao")); System.out.println(marcaPropriedade.getDescricao()); System.out.println("I am here 2"); // Create a MarcaPropriedadeGestor to add marcaPropriedade to the database MarcaPropriedadeGestor marcaPropriedadeGestor = new MarcaPropriedadeGestor(); marcaPropriedadeGestor.add(marcaPropriedade); System.out.println("I am here 3"); // Release resources marcaPropriedadeGestor.releaseResources(); // Here the registration is complete. // Now send the user to the 'Relação de Marcas de Propriedades' page RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("//Sisc/exibeMarcaPropriedade. htm"); dispatcher.forward(request, response); } } ============================================================================ ==== this is what I get from LOG: I am here 1 I am here 1 papapapapapa papapapapapa I am here 2 I am here 2 [Fri Jun 30 11:21:12 BRT 2006] info: PoolManager: registered JDBC driver oracle.jdbc.driver.OracleDriver 10 [Fri Jun 30 11:21:12 BRT 2006] info: oracle: New pool created [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Opened a new connection [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Delivered connection from pool dentro do add -inicio Select MarcaPropriedadeIdSeq.NEXTVAL from DUAL [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Opened a new connection [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Delivered connection from pool dentro do add -inicio Select MarcaPropriedadeIdSeq.NEXTVAL from DUAL [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Opened a new connection [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Delivered connection from pool [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Opened a new connection [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Delivered connection from pool [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Returned connection to pool 47 [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Returned connection to pool 48 insert into MARCAPROPRIEDADE values (?, ?) insert into MARCAPROPRIEDADE values (?, ?) I am here 3 I am here 3 [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Returned connection to pool [Fri Jun 30 11:21:13 BRT 2006] info: oracle: Returned connection to pool I am here 1 another test I am here 2 [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Delivered connection from pool dentro do add -inicio Select MarcaPropriedadeIdSeq.NEXTVAL from DUAL [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Delivered connection from pool [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Returned connection to pool 49 insert into MARCAPROPRIEDADE values (?, ?) I am here 1 another test I am here 2 [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Delivered connection from pool dentro do add -inicio Select MarcaPropriedadeIdSeq.NEXTVAL from DUAL [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Delivered connection from pool I am here 3 [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Returned connection to pool [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Returned connection to pool 50 insert into MARCAPROPRIEDADE values (?, ?) I am here 3 [Fri Jun 30 11:22:19 BRT 2006] info: oracle: Returned connection to pool ============================================================================ ============ This is the htm form that calls the servlet: <html> <head> <title>Inclui/Altera Marca Propriedade</title> <script language="javascript"> //////////////////////////////////////////////////////////////////////////// / // Set focus to the first form element // function focusFirst() { document.all("txtDescricao").focus(); } //////////////////////////////////////////////////////////////////////////// /// // Validate fields and submit form elements to servlet RegistraMarcaPropriedade // function doFormSubmit() { objfrm=document.incluiAlteraMarcaPropriedade; //Store the file path of the next servlet/jsp to be called strFilePath = "/Sisc/servlet/RegistraMarcaPropriedade" strDescricao=objfrm.txtDescricao.value; if(isSpecialChar(strDescricao) || !isChar(strDescricao)) { alert("Favor entrar com uma descrição válida."); objfrm.txtDescricao.focus(); return false; } if(isEmpty(strDescricao)) { alert("Campo obrigatório"); objfrm.TxtNumber.focus(); return false; } objfrm.method="post"; objfrm.action=strFilePath; objfrm.submit(); } //////////////////////////////////////////////////////////////////////////// /// // Clean all the fields // function doClearForm() { for(i=0;i<document.inputFormSearch.elements.length-1;i++) { if(document.inputFormSearch.elements[i].type=="text") document.inputFormSearch.elements[i].value=""; } document.all("txtDescricao").focus(); return false; } //////////////////////////////////////////////////////////////////////////// /// // Checks whether the form input element is empty // function isEmpty(formelem) { expisEmpty=/[^ ]/ return ! expisEmpty.test(formelem); } //////////////////////////////////////////////////////////////////////////// /// // Checks whether the form input element is numeric // function isNumeric(formelem) { var expisNumeric=/[a-zA-Z\*\~|@\$\%\^\&\*\(\)\#\!\`\-\+\=\.\,\?]/ return ! expisNumeric.test(formelem) } //////////////////////////////////////////////////////////////////////////// /// // Checks whether the form input element is a String // function isChar(formelem) { var expisChar=/[0-9]/; return ! expisChar.test(formelem); } //////////////////////////////////////////////////////////////////////////// /// //Checks whether the form input element contains any Special Characters or not. // function isSpecialChar(formelem) { var expisSpecialChar=/[\&\;\"\*\~\|[EMAIL PROTECTED]<\>\\\+\=\?]/ return expisSpecialChar.test(formelem) } </script> </head> <body onload="javascript:focusfirst()"> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%"> <tr> <td width="100%" colspan="3"> <img border="0" src="images/bannerPR.jpg" width="763" height="21"></td> </tr> <tr> <td width="18%"> <b> <font color="#008080" size="5">SISNAC</font><font color="#008000" size="5"> </font> </b></td> <td width="59%"> <p align="center"><font size="4"><b>Cadastramento de Nova Marca de Propriedade</b></font></td> <td width="23%"> </td> </tr> <tr> <td width="18%"> </td> <td width="82%" colspan="2" align="right"> </td> </tr> <tr> <td width="100%" colspan="3"> <p align="center"> </p> <form name="incluiAlteraMarcaPropriedade"> <p align="left"> Marca de Propriedade: <input type="text" name="txtDescricao" size="66"></p> <p align="center"> <input type="submit" value="Enviar" name="btnSubmit" onclick=" javascript:return doFormSubmit()"> <input type="reset" value="Apagar" name="btnApagar"></p> </form> <p align="center"> </p> <p align="center"> </p> </td> </tr> <tr> <td width="100%" colspan="3"> </td> </tr> </table> </body> </html> ============================================= any help is welcome!!! thanks PS: I have tried different tomcats but the problem persists. apache-tomcat-5.5.17.exe jakarta-tomcat-4.1.31.exe jakarta-tomcat-5.0.30.exe jakarta-tomcat-5.0.28.exe --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]