1 Reply Latest reply on Sep 22, 2003 4:18 AM by Jon Barnett

    JSP autuomatically reload

    gorges Newbie

      The problem is that:I'm using PreparedStatement of java to insert some records into an oracle database table with no primary key set.Sometimes the function was fine and the desired records were inserted,but sometimes when I insert one record,JBoss inserted two same records into the table,that is,the JSP seems automatically reload itself and insert the record again.
      Could anyone tell me the cause and how to solve it?


      I'm using jboss-3.2.1_tomcat-4.1.24,and have configured my oracle datasource as follows in oracle-ds.xml:

      <local-tx-datasource>
      <jndi-name>OracleDS</jndi-name>
      <connection-url>jdbc:oracle:thin:@localhost:1521:ORACLEDB</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>VISITOR</user-name>
      VISITOR
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
      </local-tx-datasource>



      The code to insert a record in my JavaBean is:
      DataSource ds = (DataSource) ctx.lookup("java:/OracleDS");
      Connection conn = ds.getConnection();
      PreparedStatement ps = conn.prepareStatement("insert into ROLE_PERMISSION(ROLENAME,PERMISSION) values(?,?)");
      ps.setString(1, role);
      ps.setString(2, perm);
      ps.executeUpdate();


      Below is my JSP.It managies the relationship between the role and the permission of the role.Role_PermMan is the JavaBean to carry out the function.In which permExists() determines if the role already has the permission,assignPerm() assigns a permission to a role,revokePerm() revokes a permission from a role.
      The "actionType" is used to determine what kind of action to take.
      Sometimes,it just insert one record;but sometimes it insert two same records.This seems completely random.I'm confused.

      <jsp:useBean id="hasConPerms" scope="page" class="SecurityMan.Role_PermMan" />
      <%
      String a=request.getParameter("actionType");
      String role=(String)session.getAttribute("mRole1");
      if(a.equals("grant")){
      String grant=(String)request.getParameter("allcperms");
      if(hasConPerms.permExists(role,grant)){
      %>
      The Role already has the permission!
      <%
      }
      else
      {
      hasConPerms.assignPerm(role,grant);
      %>
      The permission has been assigned to the role!
      <%
      }
      }
      else if(a.equals("revoke")){
      String revoke=(String)request.getParameter("hascperms");
      hasConPerms.revokePerm(role,revoke);
      %>
      The permission has been revoked form the role!
      <%
      }
      %>