Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

retrieve value from <SELECT> within the servlet

843841Oct 29 2004 — edited Oct 29 2004
HI,

I am writing this servlet in which I am creating a combo box using <SELECT> <OPTION> . I want to get the value that is selected in the combo box into a variable in the servlet itself. This could be pretty simple....but I am new to servlets...so please help. Here is my code if it helps......

package transcriptHandler;

/**
* @author gauri
*/

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import DBConnection.databaseHandler;

/* this class grabs a list of videos that the user created and asks
for location of it's audio file and then creates the transcript for
that file*/

public class Transcript extends HttpServlet
{

//variables used to grab userID, classID and run the query
String userID;
String classID;
String query;
ResultSet results;
Vector myVids;
String audioName;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();

//grab the userID and classID from the session
HttpSession session = request.getSession(true);
userID = (String) session.getAttribute("userID");
classID = (String) session.getAttribute("classID");

//create a new databaseHandler object and grab all the videos needed
databaseHandler myHandler = new databaseHandler();
myVids = new Vector();
query = "SELECT aname FROM Transcript WHERE for_class='" + classID + "' AND created_by=" + userID;
try {
results = myHandler.executeQuery(query);
while(results.next()) {
myVids.add(results.getString(1));
}
}
catch(Exception e) {
e.printStackTrace();
}

//create the actual HTML page the user will see
out.println("<HTML>");
out.println("<HEAD><TITLE>classID = " + classID + " </TITLE></HEAD>");
out.println("<BODY>");
out.println("<form name=\"trans\" action=\"\">");

out.println("<TABLE BORDER=\"0\" ALIGN=\"Center\">");
out.println("<TR><TD><H3>Select Video for creating transcript</H3></TD></TR>");
out.println("<TR><TD>Select Audio File: <SELECT NAME= \"audioName\">");
//out.println("the audio file selected is" + audioName);

for(int i=0; i< myVids.size(); i++) {
out.println("<OPTION> " + (String)myVids.elementAt(i));
}

out.println("</TR><TD>");
//I want to get the selected value here....String a =value selected from combo box.
out.println("</SELECT></TD></TR>");
out.println("<TR><TD><BR></TD></TR>");
out.println("<TR><TD>");
out.println("<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Create A\">");
out.println("</TD></TR>");
out.println("</TABLE></FORM>");


out.println("</BODY></HTML>");
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 26 2004
Added on Oct 29 2004
1 comment
509 views