Problems with request.getParameter keeping values.

cookytime
cookytime used Ask the Experts™
on
Hi,

The problem that I have is that the JSP page is remebering the request.getParameter's from previous accesses.

eg
search.jsp?day=mon&day=tue&branch=KG

Works fine the first time but

search.jsp?branch=KG

keeps the day=mon&day=tue the second time.

I'm using

String branch = request.getParameter("branch");
String dayType[] = request.getParameterValues("day");

If I reput the file on TOMCAT it works the first time but not the second.

Do I need to blank out the request.* at the end of the jsp file.

Code from the site below.  (Sorry about the code I'm still learning).

<%@ page import="java.sql.*, java.lang.*, java.util.*, java.text.*" autoFlush="true" session="false" %>

<%!
     static String username = "cookg";
     static String password = "choc45chip";
     static String branch;
     static String day[];
     static String session[];
     static String queryDayType = "like '%'";
     static String querySessionType = "like '%'";
     static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
     static String[] dayType = null;
     static String full = "no";
     static String query;
%>
<%
Class.forName("com.mysql.jdbc.Driver");

if (request.getParameter("branch") == null) {branch = "%";} else {branch = request.getParameter("branch");}
if (request.getParameter("day") != null) {
     String dayType[] = request.getParameterValues("day");

     int dayNumber = dayType.length;
     int i = 0;
     queryDayType ="in(";
     while (i < dayType.length) {
          if (i < (dayType.length - 1)) {
               queryDayType = queryDayType + "'" + dayType[i] + "',";
               } else {
               queryDayType = queryDayType + "'" + dayType[i] + "'";
               }
          i++;
          }
     queryDayType = queryDayType + ")";
     }
if (request.getParameter("session") !=null) {
     String sessionType[] = request.getParameterValues("session");

     int sessionNumber = sessionType.length;
     int i = 0;
     querySessionType ="in(";
     while (i < sessionType.length) {
          if (i < (sessionType.length - 1)) {
               querySessionType = querySessionType + "'" + sessionType[i] + "',";
               } else {
               querySessionType = querySessionType + "'" + sessionType[i] + "'";
               }
          i++;
          }
     querySessionType = querySessionType + ")";
     }

String query = "SELECT * from cfprograms left join session_codes using (session) where branch like '" + branch + "' and day " + queryDayType + " and cfprograms.session " + querySessionType + "";

Connection conn = DriverManager.getConnection("jdbc:mysql://martha.lib.dis.qut.edu.au:3306/gc_test", username, password);
java.util.Date today;
String output;
SimpleDateFormat formatter;

formatter = new SimpleDateFormat("EEE, MMM d, yyyy ");
today = new java.util.Date();
PreparedStatement stmt1 = conn.prepareStatement(query);
ResultSet rs = stmt1.executeQuery();
%>

The main page of the Page.

<%
rs.close();
conn.close();
%>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
are you trying to refresh the page?

Commented:
just below the code:
Class.forName("com.mysql.jdbc.Driver");

check to see if your request.getParameter() contains something:

System.out.println("branch: " + request.getParameter("branch"));
System.out.println("day: " + request.getParameter("day"));

also, how many pages are you actually using.... and what does each page do??? =)

Mick BarryJava Developer
Top Expert 2010

Commented:
Don't make the following variable static.

<%!
    static String username = "cookg";
    static String password = "choc45chip";
    static String branch;
    static String day[];
    static String session[];
    static String queryDayType = "like '%'";
    static String querySessionType = "like '%'";
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    static String[] dayType = null;
    static String full = "no";
    static String query;
%>
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Java Developer
Top Expert 2010
Commented:
Should be:

<%!
    String username = "cookg";
    String password = "choc45chip";
    String branch;
    String day[];
    String session[];
    String queryDayType = "like '%'";
    String querySessionType = "like '%'";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String[] dayType = null;
    String full = "no";
    String query;
%>

Commented:
i didn't see that..... actually, objects is right..... =)

Author

Commented:
Thanks heaps for that.  
Mick BarryJava Developer
Top Expert 2010

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial