Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i avoid replications?

 
Mark Antone
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have this code:
<HTML><HEAD><TITLE>Dynamic Form</TITLE></HEAD>
<BODY>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.sql.SQLException"%>
<%@ page import = "javax.sql.rowset.CachedRowSet"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "com.sun.rowset.CachedRowSetImpl"%>

<CENTER>
<%
String Name = request.getParameter("FillName");
String SubjectS = request.getParameter("subject");
String EmailP = request.getParameter("email");
String Qtype1 = request.getParameter("Question1");
String Qtype2 = request.getParameter("Question2");
String b = request.getParameter("rating");

String connectionURL
= "jdbc:mysql://localhost/createquestions";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
ResultSetMetaData metaData = null;

Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection (connectionURL, "root", "");
statement = connection.createStatement();

//to register the information for the questions generator.
String query = "insert into publishers (publisherName,publisherSubject,publisherEmail) values('"+Name+"','"+SubjectS+"','"+EmailP+"')";
int d=statement.executeUpdate(query);
.
.
.
when i click refresh icon i got same registerd information in my data base i want to avoid this replication.

Oh, if forgot the idea of this code is to resive users and register thier informations in data base allow them to choose type of questions that they want to create them.
[ March 02, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got all the code in the JSP. So of course, if the page gets refreshed, it's going to keep doing the same thing again and again and again.

Step 1: learn proper web application architecture and get that database code off the page.

Step 2: make sure that when a page is displayed, refreshing it will not cause active operations to repeat. The so-called "PRG Pattern" can help you there.
 
Mark Antone
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you show me how to disable back button and refersh button
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot reliably disable the back and refresh actions.

Besides, that would just be a band-aid approach to the problem. What you really need to do is to fix your application.

An older article on the PRG pattern (which stands for Post-Redirect-Get) can be found here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic