Solved

Unable to retrieve parametername of the selection box through a servlet

Posted on 2003-10-23
5
162 Views
Last Modified: 2010-04-01
Hi All,
 I have a JSP which when executed calls a servlet.
Tis Jsp has couple of text fields and checkboxes and two selection boxes.
WHen I make a call to get parameternames for all the components in the JSP. I aget everything except the names of the selection boxes.
Anyhelp soon will be appreciated.
Thanks
Azhar
0
Comment
Question by:aarschie
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 9610825
that's b/c you have to select an item in the selection box... otherwise no value from it will be passed (hence no parameter).
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 500 total points
ID: 9610835
just make a default option like:

<option value=-1 selected>Choose whatever</option>

then just make sure the user selects an option
0
 
LVL 4

Expert Comment

by:vk33
ID: 9612180
Make sure you've defined the names of selection boxes in the form. And check out the spelling in both the form and the servlet.

Regards!
0
 
LVL 4

Expert Comment

by:vk33
ID: 9612209
JSP code:

<form action="Demo" method="POST">
<select name="sel">
      <option value="123">bla-bla-bla</option>
</select>
<input type="submit">
</form>

Servlet code:
PrintWriter out = null;
try {
      out = response.getWriter();
      String param = request.getParameter("sel");
      out.println (param);
} catch (Exception e) {
      if (out != null)
            out.println (e.toString());
}

It works fine, I've checked...

Good luck!
0
 
LVL 4

Expert Comment

by:vk33
ID: 9612231
Khm, sorry, I misunderstood the question... Include the following to the servlet code above:

Enumeration enumParams = request.getParameterNames();
while (enumParams.hasMoreElements())
   out.println((String)enumParams.nextElement());

But still it works fine, you'll get "sel" param name printed out.
Tested on Tomcat-4.1.18

Regards!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ajax auto save 15 98
session bean client machine 9 57
reflection example 3 92
servlet init param and contect param 3 59
Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now