Strange problem
hello
I'm developing a small code to display models and submodels for cars.
when one clicks on a submenu, it calls SubModelServlet, where I
populate models from database into a vector object, put into request
object and dispatches to ModelView.jsp page.
where I display list of models into drop down box.<select></tag>
In short, problem is every time i visit the page, it doubles the
content items in drop down box.
code for above
//When one clicks on SubMenu it navigates to SubMenuServlet where foll.
is done.
stmt=conn.createStatement();
String query="select * from \"ModelMaster\"";
res=stmt.executeQuery(query);
while(res.next())
{
ConcreteModelDTO modelDTO=new ConcreteModelDTO();
modelDTO.setMIndex(res.getInt("MIndex"));
modelDTO.setModel(res.getString("model"));
vModel.addElement(modelDTO);
}
res.close();
stmt.close();
request.setAttribute("models",vModel);
rd=getServletContext().getRequestDispatcher("/SubModelView.jsp");
rd.forward(request,response);
SubModelView.jsp
<%
StringBuffer modelOption=new StringBuffer();
Vector
vModel=(Vector)request.getAttribute("models");
Iterator it=vModel.iterator();
while(it.hasNext())
{
ConcreteModelDTO
modelDTO=(ConcreteModelDTO)it.next();
modelOption.append("<option
value=\""+modelDTO.getMIndex()+"\">"+modelDTO.getModel()+"</option>");
}
%>
<html>
<head >
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>Model</title>
</head>
<body>
<td><h4>Model Type</h4></td>
<td>
<%= "<select name=\"cmbModel\" id=\"cmbModel\">"+modelOption
+"</select>"%>
</td>
<td><h4>Sub Model Type</h4></td>
<td><input type=text id="txtSubModel"></td>
<tr>
<td><INPUT type=button value="Create SubModel"
name="btnCreate" class='btn' onclick="selectModel(this)"></td>
</tr>
</table>
</table>
Every time i calls jsp page, either by through clicking on menu or
refreshing, it shows the page but with doubled drop down contents.
please help me out.