<%
Vector dept_Vect = new Vector();
%>
<TD> DEPARTMENT :
<SELECT NAME="department" tabindex ="3">
<Option value ="select"> Select Department --</option>
<% for(int i =0 ;i < dept_Vect.size(); i++)
{%> <option value="<%=dept_Vect.elementAt(i) %>"><%=(String)dept_Vect.elementAt(i) %>
out.println(dept_Vect + "value of dept");
</option>
<%}%>
public New_USER find(String sql, Object dept_Vect) throws DaoException, ClassNotFoundException {
Connection connection =null;
PreparedStatement preparedStatement = null;
ResultSet resultSet =null;
New_USER newuser = null;
try{
newuser = new New_USER();
connection = connectsql.getConnection();
System.out.println(connection);
preparedStatement = connection.prepareStatement(SQL_DEPARTMENT);
System.out.println(SQL_DEPARTMENT);
System.out.println(preparedStatement + "checking for department");
resultSet =preparedStatement.executeQuery();
System.out.println(resultSet);
// dept_Vect.removeAllElements();
while(resultSet.next()){
String nextloc = (String)resultSet.getString(1);
dept_Vect.addElement(nextloc);
private static final String SQL_DEPARTMENT =
"select deptname from base_department" ;
Paul Sturrock wrote:Does your query return any results?
Mohamed Inayath wrote:
Will only create the vector.
From where you are getting the values.
Always the Vector will be empty right.
Nitin Belaram wrote:
I had created vector in jsp page and defining method to get value in dropdown from database via using servlet
Dawn Charangat wrote:Nitin, what you are doing is correct, except for that glitch pointed out by Mohamed.
You are getting the data alright in your servlet after the database query, but you are not sending that data to the JSP page... Just by using the same name [dept_Vect] in both the servlet and JSP will not make sure that the data is transfered... You will have to probably store this information from the servlet to a request object or session object :
eg:
Vector dept_Vect = (Vector)request.getAttribute(the_name_you_gave_to_set_in_request); // if you are setting it in request
OR
Vector dept_Vect = (Vector)session.getAttribute(the_name_you_gave_to_set_in_session); // if you are setting it in session
try this out and see if your drop-down is populated correctly.
Mohamed Inayath wrote:Nitin, Can you add the complete code where you are getting the mentioned errors?
Dawn Charangat wrote:Wonderful.... now that I look back, I think I might have confused you with a few things.
You need to put the dept_Vect object you created in the SERVLET to request or session.
eg: request.setAttribute("dept_Vect", dept_Vect) OR session.setAttribute("dept_Vect", dept_Vect)
and then, in your JSP, you should access it like :
Vector dept_Vect = (Vector)request.getAttribute("dept_Vect") OR Vector dept_Vect = (Vector)session.getAttribute("dept_Vect")
and NOT Vector dept_Vect = new Vector()
is it clear to you now ???
EMP F NAME : <INPUT type="text" size="20" maxlength="15" name="empfname" > | EMP L NAME : <INPUT type="text" size="20" maxlength="15" name="emplname"> |
DEPARTMENT : <SELECT NAME="department" tabindex ="3"> <Option value ="select"> Select Department --</option> <% for(int i =0 ;i < dept_Vect.size(); i++) {%> <option value="<%=dept_Vect.elementAt(i) %>"><%=(String)dept_Vect.elementAt(i) %> out.println(value); </option> <%}%> </SELECT> | DESIGNATION : <Select Name ="designation"> <option value ="select" >Select Designation --</option> <% for(int i = 0;i< desg_Vect.size();i++) { %> <option value ="<%= desg_Vect.elementAt(i) %>"> <%=(String)desg_Vect.elementAt(i) %></option> <%} %> </Select> |
EMAIL-ID : <INPUT type="text" size="20" maxlength="15" name="emailid" > | ADDRESS : <INPUT type="text" size="20" maxlength="15" name="address" > |
PROJECT : <INPUT type="text" size="20" maxlength="15" name="project" > | MANAGER : <INPUT type="text" size="20" maxlength="15" name="manager" > |
Mohamed Inayath wrote:Change the code with the below one and update..
Dawn Charangat wrote:I presume, that this method [public New_USER find()] is inside a servlet. In that case, you dont have to do :
((Object) request).setAttribute("dept_Vect", dept_Vect) ; //Which infact is wrong, and thats why the compiler complains
You should be using:
request.setAttribute("dept_Vect", dept_Vect) ; // Where "request" is of type HttpServletRequest
Mohamed Inayath wrote:Change the code with the below one and update..
Mohamed Inayath wrote:Have you changed the JSP as well??
Code you post the complete JSP within code tags..
EMP F NAME : <INPUT type="text" size="20" maxlength="15" name="empfname" > | EMP L NAME : <INPUT type="text" size="20" maxlength="15" name="emplname"> |
DEPARTMENT : <SELECT NAME="department" tabindex ="3"> <Option value ="select"> Select Department --</option> <% for(int i =0 ;i < dept_Vect.size(); i++) {%> <option value="<%=dept_Vect.elementAt(i) %>"><%=(String)dept_Vect.elementAt(i) %> out.println(value); </option> <%}%> </SELECT> | DESIGNATION : <Select Name ="designation"> <option value ="select" >Select Designation --</option> <% for(int i = 0;i< desg_Vect.size();i++) { %> <option value ="<%= desg_Vect.elementAt(i) %>"> <%=(String)desg_Vect.elementAt(i) %></option> <%} %> </Select> |
EMAIL-ID : <INPUT type="text" size="20" maxlength="15" name="emailid" > | ADDRESS : <INPUT type="text" size="20" maxlength="15" name="address" > |
PROJECT : <INPUT type="text" size="20" maxlength="15" name="project" > | MANAGER : <INPUT type="text" size="20" maxlength="15" name="manager" > |
Mohamed Inayath wrote:Oops..typo error :
where to put these code in jsp and servletMohamed Inayath wrote:So it means...
The values you set in the Request scope is getting lost.
Try setting in the session.
Inservlet :
In JSP
Mohamed Inayath wrote:Sorry dont need to have
HttpSession session = request.getSession(false) within JSP
Session is a impicit object..
Discard
HttpSession session = request.getSession(false)
Mohamed Inayath wrote:
Mohamed Inayath wrote:Hey,
Is it you are calling JSP and then submitting the form values to the Servlet.
JSP-->Servlet.
If this is true then yes it will always return empty list.
Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|