why form submit to a servlet could not retrive the parameter values?

I have a form which has tag like this:

<form name="frm1" action="servlet">

I found I could only retrieve request.getParameter() in the servlet to retrieve hidden type parameter values, not the form object parameter value. so, if I want to get the value from a text field, the request.getParameter() return null.

Why? How to fix ?
Who is Participating?
you should be able to
are the text fileds inside the form, and are you using the correct name
changcy77Author Commented:
I have checked all those and could not find anything missing.
changcy77Author Commented:
The only other thing is I use a javascript to validate some fields before submit sent out request.

<form name=..  action=...onSubmit=validate()>
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

is text field  inside <form..> </form>?
Manikandan ThiagarajanSenior consultantCommented:
give correct textfieldname or variable name in request.getParameter("text1");
The form name and event listeners (onChange, onSubmit, etc) are not relevant to this discussion since they are only used in javascript (client-side) whereas the values that are submitted are processed in the servlet (server-side).

The following form would work:

<form action="testServlet" method="get">

<input type='text' name="name" size='20' value='This is my name'>

<input type="submit"><input type="reset">


In the servlet itself you will have a method called doGet(HttpServletRequest request, HttpServletResponse response).

This is what is called by a form with method "get". To read the form field values, use request.getParameter(parameterName) so in the above example
String name = request.getParameter("name") would result in a new string variable called name which would  have a value of "This is my name"

String name = request.getParemter("name") ;
if (name == "This is my name") {
   name = "" ;
} else {
   // do something
One thing to note, if the control is disabled then it doesn't post anything with the form...

Not sure if this applies here...

Just thought I'd chime in ;-)


        Can you post or look at your self about your html code in your browser? You have to make sure that there is a text field which also needs to be inside

I found it is actually a stupid mistake that I have one text field and one select filed that both have the same names since they represent the same entries(one for new entry, one for choosing from existing entries). so, since only one of them got entered, so the empty one passed the null value to request.

On the other hand, what would be a good solution for this problem? I could either name them differently or there is other better way of doing this? thanks.
if they represent different things, you have to name them differently. otherwise,  you could try request.getParamters(..)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.