wood burning stoves 2.0*
The moose likes JSP and the fly likes How can i avoid replications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How can i avoid replications?" Watch "How can i avoid replications?" New topic

How can i avoid replications?

Mark Antone

Joined: Feb 28, 2006
Posts: 4
i have this code:
<%@ 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"%>

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;

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

Joined: Jan 10, 2002
Posts: 60782

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Antone

Joined: Feb 28, 2006
Posts: 4
can you show me how to disable back button and refersh button
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60782

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: How can i avoid replications?
Similar Threads
my servlet can't initialize: null
SQL error
need help. I have problems running the client
How to store option format value in database in jsp
Help with servlets