Solved

Unable to retrieve parametername of the selection box through a servlet

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
build fail in maven project 11 171
How to set default webapp for host 6 41
oracle fusion vs MQ 2 93
struts hibernate integration example 28 113
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

22 Experts available now in Live!

Get 1:1 Help Now