Solved

Unable to retrieve parametername of the selection box through a servlet

Posted on 2003-10-23
5
163 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

An article on effective troubleshooting
This problem is more common than not and I will show you some things to check to solve this problem.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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