473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JSP/Servlet: Is Form field Defined

Hello folks I am working on a project using JSP's and Servlets. I have
a servlet that handles requests from several dynamic HTML forms. I
want to know if there is a way to check wether an HTML form field was
defined. In ColdFusion there is an isDefined() function. Right now I
am checking wether the request.getParameter("formfield") is null.
this has problems with fields left empty as nulls mean something in
this form. What is the best way to accomplish this??

DM
Jul 17 '05 #1
4 5584
Joe
In article <c8*************************@posting.google.com> ,
Di***********@hotmail.com says...
I want to know if there is a way to check wether an HTML form field was
defined.


I think I'd do it this way:
public isDefined(HttpServletRequest req, String fieldNameToSearchFor) {
return req.getParameterMap().containsKey(fieldNameToSearc hFor);
}



--

Fuck George W. Bush!!!
Jul 17 '05 #2
Joe
In article <MP************************@sfo.news.speakeasy.net >,
sf***@spamcop.net says...
In article <c8*************************@posting.google.com> ,
Di***********@hotmail.com says...
I want to know if there is a way to check wether an HTML form field was
defined.


I think I'd do it this way:
public isDefined(HttpServletRequest req, String fieldNameToSearchFor) {
return req.getParameterMap().containsKey(fieldNameToSearc hFor);
}


oops, I meant:

public boolean isDefined(HttpServletRequest req, String fieldToSearchFor)
{
return req.getParameterMap().containsKey(fieldToSearchFor );
}
Jul 17 '05 #3
It sounds like you already have the solution to this problem... check
for null. Fields that are left empty will return an empty string
("").

Alternatively, you could have a hidden input field that lists all the
fields on the screen. When it submits, parse this field first to get
your "valid" parameters.

-Nathan

Di***********@hotmail.com (DiggidyMack69) wrote in message news:<c8*************************@posting.google.c om>...
Hello folks I am working on a project using JSP's and Servlets. I have
a servlet that handles requests from several dynamic HTML forms. I
want to know if there is a way to check wether an HTML form field was
defined. In ColdFusion there is an isDefined() function. Right now I
am checking wether the request.getParameter("formfield") is null.
this has problems with fields left empty as nulls mean something in
this form. What is the best way to accomplish this??

DM

Jul 17 '05 #4
Joe <sf***@spamcop.net> wrote in message news:<MP************************@sfo.news.speakeas y.net>...
In article <c8*************************@posting.google.com> ,
Di***********@hotmail.com says...
I want to know if there is a way to check wether an HTML form field was
defined.


I think I'd do it this way:
public isDefined(HttpServletRequest req, String fieldNameToSearchFor) {
return req.getParameterMap().containsKey(fieldNameToSearc hFor);
}

Joe, your a life saver. before I saw your post I popped all of the
results into an enumeration list and checked them manually. Your ways
is Definately much better. Thanks
public boolean isFormFieldDefined(HttpServletRequest request, String
x)
throws ServletException, IOException
{
String tests = "a";
String chkfield = x;
boolean def = false;
Enumeration enum = request.getParameterNames();
while (enum.hasMoreElements())
{
tests = (String)enum.nextElement();
if(tests.equals(chkfield))
{
def = true;
break;
}
}
return def;
}//end isFormFieldDefined.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DiggidyMack69 | last post by:
I am creating a servlet to process a dynamically created form like below. Each instance of the field test has it's index number concatenated to it. There is also the numset field that let's me...
1
by: efiedler | last post by:
Hi - I have the following input field on my html page: <input type="image" name="submit" id="submit" src="c:\image.jpg" value="image.jpg"> I also have another input field on the form that is...
2
by: Garg | last post by:
Hi All, I am facing one problem if you are having any solution please tell me. I have to pass an array from javascript to servlet. for this i created one array and pass that through submitting...
0
by: ErikaW | last post by:
Hi all, I've tried to google this but could not find a clear solution. I have a Web application developed in JDevloper using mostly html and Javascript. I have a pre-defined PDF form which I merge...
14
by: ramadeviirrigireddy | last post by:
Hi All, I have the following code for form and servlet. when the form is submitted the servlet will print the values passed by the form. i'm not getting the servlet o/p when i submit the...
0
by: krishna81m | last post by:
Could some one please explain why the session is not being maintained when I am doing a forward in a servlet after setting a cookie. I am even unable to set session attributes or parameters and...
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
1
by: Silgd1 | last post by:
Hi All, I am trying to pass parameters from a mutiple selection listbox contained in a visual web jsf page to a servlet. I am using netbeans 6.0.1, and already have a method written in the java...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.