File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSP
Bookmark "How can i avoid replications?" Watch "How can i avoid replications?" New topic
Author

How can i avoid replications?

Mark Antone
Greenhorn

Joined: Feb 28, 2006
Posts: 4
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

Joined: Jan 10, 2002
Posts: 60053
    
  65

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
Greenhorn

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

Joined: Jan 10, 2002
Posts: 60053
    
  65

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
SQL error
my servlet can't initialize: null
need help. I have problems running the client
Help with servlets
How to store option format value in database in jsp