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

[797 byte] By [Martin_OSheaa] at [2007-11-27 11:52:16]
# 1

> String str = request.getParameter("slope");

This line should be written in the action doer of the <form>. Typically it is another servlet.

hiwaa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 2

Use,

String str = request.getAttribute("slope");

skp71a at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 3

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.

Martin_OSheaa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 4

String str = request.getAttribute("slope");

This should ideally help

sun_java_helpa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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 > top of Java-index,Java Essentials,Java Programming...
# 6

I have tried:

String slope = (String) request.getAttribute("slope");

But again, all I get is null.

Any ideas?

Martin_OSheaa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 7

How then can I extract the value the user enters for slope into a Java variable?

Any ideas?

Martin_OSheaa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 8

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

sandeep_2012a at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 9

> 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 > top of Java-index,Java Essentials,Java Programming...
# 10

This is now resolved. Many thanks.

Martin_OSheaa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...
# 11

> This is now resolved. Many thanks.

Oh, congrats.

Will you please post how it is resolved, for the sake of us forum friends?

hiwaa at 2007-7-29 18:43:24 > top of Java-index,Java Essentials,Java Programming...