Friday 15 July 2011

servlets - How to send id from dropdown populated student name in jsp? -


I'm receiving studentName and studentId from database databases. Now after selecting the special studentName from the dropdown, how to send studentId from jsp to the servlet here is my code:

   & Lt; / Options & gt; & Lt; / C: foreach & gt; & Lt; / Select & gt;    

You need to include your dropdown in the form and act as your servlet should do. & lt; Form method = "POST" action = "servletName" & gt; & Lt; Choose Name = "studentdetails" id = "std" & gt; & Lt; C: forEach item = "$ {stdList}" var = "std" & gt; & Lt; Option value = "1" & gt; & Lt; C: out value = "$ {std.name}" /> & Lt; / Options & gt; & Lt; / C: foreach & gt; & Lt; / Select & gt; & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt;

In your doPost servlet method, you can retrieve the parameters using,

  request.getParameter ( "Studentdetails");   

Note that you & lt; Input type = "submit" value = "submit" & gt; and the post method you are using, this method will call the doPost method of the servlet allletname is the name of the sublet that is deployed The descriptor is mapped to web.xml .

  & lt; Servlet & gt; & Lt; Servlet-name & gt; YourServlet & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Com.example.YourServlet & lt; / Servlet category & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; YourServlet & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / YourServlet & lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt;    

No comments:

Post a Comment