nubee
asked on
How to refresh the values in the vector with new values
Hello all,
I am using a Bean to get the data from the database and populating that data using jsp. Vector is used to store the data from the resultset.
This is the scenario: SearchPage.jsp. User selects a vendor from listbox, Model from listbox and column from listbox and when hits enter
ResultsPage.jsp opens up and Result is displayed in a table.
Step 2: If the user wants to search another thing, he hits back button on the form and gets to SearchPage.jsp. Hits Reset button which refreshes the form. And when the user selects the desired fields and hits Enter this time. He should only get the results from the 2nd query.
But, the code I am writing is allowing him to return the result from the 1st query and 2nd query in other words the new results are getting appended to the old values in the vector. I tried using vector.clear() method but when I used this the first result is also getting emptied nothing is showed in the result page.
This is the code I have written so far,
ResultBean.Java:
public class ResultBean {
private Connection conn;
Statement st;
ResultSet rs;
boolean processError = false;
String ve;
String mo;
String co;
String Ven=null;
String Mod=null;
String Col=null;
String colval_base;
Vector colval_vec = new Vector();
String flag = "false";
private String dbDriver="sun.jdbc.odbc.Jd bcOdbcDriv er";
public ResultBean() throws ClassNotFoundException, SQLException{
Class.forName(dbDriver);
conn=DriverManager.getConn ection("jd bc:odbc:pl anningdb", "", "");
}
public void setMod(String Value) {
this.Mod = Value;
}
public String getMod() {
return this.Mod;
}
public void setVen(String Value) {
this.Ven = Value;
}
public String getVen() {
return this.Ven;
}
public void setCol(String Value) {
this.Col = Value;
}
public String getCol() {
return this.Col;
}
public void processRequest(HttpServlet Request request,HttpSession session)throws ServletException,IOExcepti on {
ve = request.getParameter("Ven" );
mo = request.getParameter("Mod" );
co = request.getParameter("Col" );
try{
st=conn.createStatement();
rs=st.executeQuery("Select Distinct [" +request.getParameter("Col ")+ "] from [Base Inventory Table] where Vendor = '"+request.getParameter("V en")+"' and Model = '"+request.getParameter("M od")+"'");
while(rs.next()) {
colval_base = rs.getString(1);
}
}catch(SQLException e){}
}
public String getColval_base() {
return this.colval_base;}
public Object getColval_vec() {
return this.colval_vec; }
}
Main Page.sp: Code was written to clear the values in the vector when Reset button in the SearchPage.jsp was hit.
<!--This is the controlling jsp.It forwards requests and contrl to the appropriate JSP-->
<html>
<head>
<title>
MainPage
</TITLE>
</head>
<BODY>
<%@ page language="java" session="true" %>
<%@ page import = "java.util.*" %>
<jsp:useBean id="ResultBean" scope="session" class="projBeans.ResultBea n" />
<jsp:setProperty name="ResultBean" property="*" />
<% if(request.getParameterNam es().hasMo reElements () == false){ %>
<jsp:forward page="InitialPage.jsp" />
<% }%>
<% if(request.getParameter ("Enter") !=null) {%>
<jsp:forward page="CheckEmpPage.jsp" />
<% }%>
<% if(request.getParameter ("Go") !=null) {%>
<jsp:forward page="ResultsPage.jsp" />
<% }%>
<% if(request.getParameter ("Reset") !=null) {
ResultBean.processRequest( request,se ssion);
Vector colval_vec = new Vector ((Vector) ResultBean.getColval_vec() );
colval_vec.clear();
}%>
<% String choice = request.getParameter("choi ce");
if(choice.equals("search") ) { %>
<jsp:forward page="SearchPage.jsp" />
<% }
if(choice.equals("administ er") ) { %>
<jsp:forward page="LoginPage.jsp" />
<% } %>
</BODY>
</HTML>
Sorry for the length,
Please help,
Thanks
Nubee
I am using a Bean to get the data from the database and populating that data using jsp. Vector is used to store the data from the resultset.
This is the scenario: SearchPage.jsp. User selects a vendor from listbox, Model from listbox and column from listbox and when hits enter
ResultsPage.jsp opens up and Result is displayed in a table.
Step 2: If the user wants to search another thing, he hits back button on the form and gets to SearchPage.jsp. Hits Reset button which refreshes the form. And when the user selects the desired fields and hits Enter this time. He should only get the results from the 2nd query.
But, the code I am writing is allowing him to return the result from the 1st query and 2nd query in other words the new results are getting appended to the old values in the vector. I tried using vector.clear() method but when I used this the first result is also getting emptied nothing is showed in the result page.
This is the code I have written so far,
ResultBean.Java:
public class ResultBean {
private Connection conn;
Statement st;
ResultSet rs;
boolean processError = false;
String ve;
String mo;
String co;
String Ven=null;
String Mod=null;
String Col=null;
String colval_base;
Vector colval_vec = new Vector();
String flag = "false";
private String dbDriver="sun.jdbc.odbc.Jd
public ResultBean() throws ClassNotFoundException, SQLException{
Class.forName(dbDriver);
conn=DriverManager.getConn
}
public void setMod(String Value) {
this.Mod = Value;
}
public String getMod() {
return this.Mod;
}
public void setVen(String Value) {
this.Ven = Value;
}
public String getVen() {
return this.Ven;
}
public void setCol(String Value) {
this.Col = Value;
}
public String getCol() {
return this.Col;
}
public void processRequest(HttpServlet
ve = request.getParameter("Ven"
mo = request.getParameter("Mod"
co = request.getParameter("Col"
try{
st=conn.createStatement();
rs=st.executeQuery("Select
while(rs.next()) {
colval_base = rs.getString(1);
}
}catch(SQLException e){}
}
public String getColval_base() {
return this.colval_base;}
public Object getColval_vec() {
return this.colval_vec; }
}
Main Page.sp: Code was written to clear the values in the vector when Reset button in the SearchPage.jsp was hit.
<!--This is the controlling jsp.It forwards requests and contrl to the appropriate JSP-->
<html>
<head>
<title>
MainPage
</TITLE>
</head>
<BODY>
<%@ page language="java" session="true" %>
<%@ page import = "java.util.*" %>
<jsp:useBean id="ResultBean" scope="session" class="projBeans.ResultBea
<jsp:setProperty name="ResultBean" property="*" />
<% if(request.getParameterNam
<jsp:forward page="InitialPage.jsp" />
<% }%>
<% if(request.getParameter ("Enter") !=null) {%>
<jsp:forward page="CheckEmpPage.jsp" />
<% }%>
<% if(request.getParameter ("Go") !=null) {%>
<jsp:forward page="ResultsPage.jsp" />
<% }%>
<% if(request.getParameter ("Reset") !=null) {
ResultBean.processRequest(
Vector colval_vec = new Vector ((Vector) ResultBean.getColval_vec()
colval_vec.clear();
}%>
<% String choice = request.getParameter("choi
if(choice.equals("search")
<jsp:forward page="SearchPage.jsp" />
<% }
if(choice.equals("administ
<jsp:forward page="LoginPage.jsp" />
<% } %>
</BODY>
</HTML>
Sorry for the length,
Please help,
Thanks
Nubee
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no problem
Josh
Josh
ASKER
Thanks a lot. It helped a lot.