Gettting values from HTML elements in a servlet
Hello
I have some Java and embedded HTML code in a servlet which is asking the user to enter a value as below:
out.println("<form name=\"generategraph\" action=\"/monolith2/graphingoutput\" method = \"get\">");
out.println("<h3>Pick slope for graph type</h3>" +
"<input type = \"text\" name = \"slope\" size = \"3\" value = \"1\" align = \"right\>");
out.println("<input type = \"submit\" value = \"Generate graph\"></form>\n");
However, I cannot access the contents of the element slope which I need to validate. I have tried:
String str = request.getParameter("slope");
But without success; I simply get null.
Have you any ideas?
Thanks
Martin O'Shea.
Message was edited by:
Martin_OShea
skp71
I tried:
out.println("<form name=\"generategraph\" action=\"/monolith2/graphingoutput\" method = \"get\">");
out.println("<h3>Pick slope for graph type</h3>" +
"<input type = \"text\" name = \"slope\" size = \"3\" value = \"1\" align = \"right\>");
out.println("<input type = \"submit\" value = \"Generate graph\"></form>\n");
String str = (String) request.getParameter("slope");
But without success: I still get null
Have I done something wrong?
Martin O'Shea.
> String str = request.getAttribute("slope");
>
> This should ideally help
Wrong. It is not a request attribute. The request.getParameter() call should work if it is called from within the servlet mapped from /monolith2/graphingoutput action and the servlet is properly written. Read the javadoc for the javax.servlet.ServletRequest.getParameter() method.
hiwaa at 2007-7-29 18:43:24 >

better must use doget() to write html contain & post to dopost()inside it use the
request.getparameter("veriablename");
otherwice use JSP .it better than servlet
> How then can I extract the value the user enters for
> slope into a Java variable?
>
> Any ideas?
No other way than getParameter("slope"). I think your action servlet is not properly written. Show your servlet doGet() code. Can you get other parameters normally on the same servlet?
hiwaa at 2007-7-29 18:43:24 >
