Java 如何在jsp中检索选择标签值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18017094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:49:03  来源:igfitidea点击:

how to retrive select tag value in jsp?

javahtmljsp

提问by Kapil

hello i am devloping new jsp web site and i want to retrieve value from drop downlist my code is given below.

你好,我正在开发新的 jsp 网站,我想从下拉列表中检索值,我的代码如下。

                   <tr><td>Room Name</td><td><input type="text" name="roomname"></td></tr>

                 <tr><td>Room Type</td><td><select id="roomtypeid" name="roomtypeid">
                    <option  value="2L">Conference(1-25 user) </option>
                    <option  value="1L">restricted(1-50 user) </option>
                    <option  value="0L">interview (1-1 meeting with recording) </option>
                </select> 

in another page i am trying to get value of textbox like below.

在另一个页面中,我试图获取如下文本框的值。

             java.lang.String name =request.getParameter("roomname");

this run perfectly but when i try to get value from dropdown. i get null value.i try following code.

这运行完美,但是当我尝试从下拉列表中获取价值时。我得到空值。我尝试以下代码。

 out.println("your selection is..." + request.getParameter("roomtyperoomtypeid"));

kindly help me how to retrive value from dropdown.

请帮助我如何从下拉列表中检索值。

采纳答案by iaindownie

Should

应该

out.println("your selection is..." + request.getParameter("roomtyperoomtypeid"));

actually be:

实际上是:

out.println("your selection is..." + request.getParameter("roomtypeid"));

回答by Pradeep Simha

Change this:

改变这个:

request.getParameter("roomtyperoomtypeid"))

To:

到:

request.getParameter("roomtypeid"))

You were trying to access non-existing element, so null pointer exception.

您试图访问不存在的元素,因此空指针异常。