I want to retrieve data which is in input text at
jsp page.
Onclick calls javascript function in which i will submit it to
servlet.
And that input text value should be retrieve at my servlet.When i use request.getParameter in servlet it results into
null
this is my jsp page
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Diamond DNA</title>
<link type="text/css" rel="stylesheet" href="css/fixhdr.css"/>
<link type="text/css" rel="stylesheet" href="css/venus.css"/>
<script src="autosuggest.js" type="text/javascript" language="javascript"></script>
</head>
<body>
<form name="f11" id="f1" action="servlet1" method="POST">
<input type="text" id="nd" size="10">
<input type="hidden" id="hidtxt" name="hidtxt">
<input type="button" value="Click" onclick="return transfer()">
</form>
</body>
</html>
this is js page
function transfer()
{
if(document.getElementById("nd").value=="" ||document.getElementById("nd").value==null)
{
alert("");
return false;
}
document.getElementById('f1').submit();
return true;
}
This is servlet page
public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
out.close();
}
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the reply.</p>");
out.println("</body></html>");
String nb=request.getParameter("nd");
out.println(nb);
out.close();
}
}