possible caching problem? urgent help needed 10 duke dollar reward!!!
I have the following servlet which gets data from a database and displays it. The data brought back from the database comes from a drop down box on a servlet which comes before this page.
My problem is if i pick the category Drama it brings all the drama films back, but if i then press the back button in the browser and do a search for Comedy it displays all the drama films followed by the comedy films. I was told this could be something to do with a cache i tried putting in no-cache headers in the html put had no luck
Can somebody please help me 10 duke dollars to the best solution!!
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
publicclass Catalogextends HttpServlet{
String title;// what session displays
publicstaticint MAX_COUNT = 100;
int curr_item = 0;
privatestatic CatalogItem addedItem[] =new CatalogItem[MAX_COUNT];
privatestatic CatalogItem items[] =new CatalogItem[MAX_COUNT];
CatalogItem item;
CatalogItem details;
publicstatic CatalogItem getItem(int recordingid){
CatalogItem item;
for(int i=0; i<items.length; i++){
item = items[i];
addedItem[i] = items[i];
if (recordingid==item.getrecordingid()){
return(item);
}
}
return(null);
}
publicvoid doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
HttpSession session = request.getSession();
String username = (String)session.getAttribute("username");
if (username ==null){
title ="You are not logged in you may not rent or purchase dvds";
}else{
title = username +" logged in";
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Database connection code starts here
int recordingidDB;
String directorDB;
String titleDB;
String categoryDB;
String imageDB;
int durationDB;
String ratingDB;
String yearDB;
float priceDB;
int StockDB;
Connection conn =null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(Exception e){
System.out.println(e);
}
// connecting to database
try{
conn = DriverManager.getConnection
("jdbcMYURL GOES HERE");
}
catch(SQLException se){
System.out.println(se);
}
// Create select statement and execute it
try{
String category = request.getParameter("category");
String selectSQL ="select recording_id, director, title, category, image_name, duration, rating, year_released, price, stock_count "+
"from video_recordings " +
" where category = " +"'" + category +"'";// maybe do a count of rec id where cat is "cat"
System.out.println(selectSQL);
Statement stmt = conn.createStatement();
ResultSet rs1 = stmt.executeQuery(selectSQL);
while(rs1.next() && curr_item >< MAX_COUNT){
recordingidDB = rs1.getInt("recording_id");
directorDB = rs1.getString("director");
titleDB = rs1.getString("title");
categoryDB = rs1.getString("category");
imageDB = rs1.getString("image_name");
durationDB = rs1.getInt("duration");
ratingDB = rs1.getString("rating");
yearDB = rs1.getString("year_released");
priceDB = rs1.getFloat("price");
StockDB = rs1.getInt("stock_count");
item =
new CatalogItem
(recordingidDB, directorDB, titleDB, categoryDB, imageDB, durationDB, ratingDB, yearDB, priceDB, StockDB);
addedItem[curr_item] = item;
items[curr_item++] = item;
}
int ITEM_COUNT = curr_item;
String pagetitle ="Catalog Items";
out.println(
"<BODY BGCOLOR=\"#a00e0e\">\n" +
"<center></center>\n" +
"<p align=\"right\"><font color=\"White\"><H5>" + title +"</H5></font color></P>\n" +
"<H1 ALIGN=\"CENTER\">" + pagetitle +"</H1>\n");
// loop to go over each item in the array of catalogItem
for(int i=0; i<addedItem.length; i++){
details = items[i];
if (details ==null){
out.println("SORRY THERE HAS BEEN AN ERROR ");
}else{
for(int j=0; j><MAX_COUNT; j++){
formURL = response.encodeURL(formURL);
out.println(
addedItem[j].gettitle() +"\n" +
addedItem[j].getprice() +"\n" +// put as something else its not right price
addedItem[j].getstock() +"\n" +// need to populate stock!!
}
out.println("></BODY></HTML>");
}
}
stmt.close();
conn.close();
}catch(SQLException se){
System.out.println(se);
}
}
}
I need help with this so please can somebody help me?

