Hi,
In one of the
Jsp page, i am having a combo box which will display the static data. Upon selecting the value from the drop down combo box and clicking on button, it will navigagte to the
servlet and will display the selected value from the combo box.
Below are the codings for JSP and servlets. My problem here is, selected value of the combo box is not passing to the servlet.
Please tell me, where am i doing wrong and please give me the correct code. ( i am sure my JSP coding is not correct.)
I am not sure, whether this question belongs to Servlet forum or JSP forum, hence i am posting in both the places.
JSP.
-----------------------------------------------------
<html>
<head>
<title>Combo
</title>
</head>
<body>
<form method=post action="http://localhost:8080/servlets/test/radio">
<select id='cmb'>
<option>SERVLET</option>
<option>SERVLET1</option>
<option>SERVLET2</option>
</select>
<input type=submit value="OK">
</form>
</body>
</html>
---------------------------------------------------------------
Servlet
-----------------------------------------
package
test;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class radio extends HttpServlet{
public void init(ServletConfig sc) throws ServletException//, IOException
{
System.out.println("Into Init of test1");
super.init(sc);
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String str=req.getParameter("cmb");
if(str!=null){
out.println("You have selected "+str);
}
else{
out.println("You have not selected any thing");
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
doPost(req,res);
System.out.println(req.getMethod());
}
}
-------------------------------------------------------------------------------
Thanks in Advance,
Narasimha.