如何从jsp的DropDown菜单中捕获值到Servlet?(how can I capture the value from a DropDown menu at jsp to Servlet?)

编程入门 行业动态 更新时间:2024-10-28 07:21:16
如何从jsp的DropDown菜单中捕获值到Servlet?(how can I capture the value from a DropDown menu at jsp to Servlet?)

我想在我的JSP上使用下拉菜单,但是...我不知道如何捕获所选项的值并将其传递给我的Servlet,并有一些QUERY将值添加到我的数据库中。

你能给我一些想法或线索如何编码吗?

PS。 我还需要将下拉菜单中的项目转换为整数,因为我将把它添加到我的数据库中的存储数据中。

这对像我这样的初学者来说难吗? 我应该使用Textbox并让用户手动输入INTEGER而不是Dropdown菜单吗?

非常感谢提前:)

我的Jsp 菜单是这样的:

<body> <form action="AddPoints"> <table width="408" border="0"> <tr> <td width="402"><h3 align="center">Enter Points:</h3> <h3 align="center"> <label for="Points"></label> <select name="Points" size="1" id="Points"> <option value="5" selected>5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> </select> <br/> </h3> <h3 align="center"><strong></strong> <input type="submit" name="AddPoints" id="AddPoints" value="Add Points"> </h3></td> </tr> </table> </form> </body>

另外我想知道这一行的 : <option value="25">25</option>是我的servlet可以捕获的实际值吗?

对不起,如果我有这么多问题...... :)

I want to use a dropdown menu on my JSP but... I have no idea how to capture the Value of the Selected Item and Pass it on to my Servlet and have some QUERY to add the value to my database.

Can you give me some idea or clue how to code it?

PS. I also need items at dropdown menu converted into an Integer cause i'll be adding it to the stored data at my database.

Will this be hard for a starter like me? should I use Textbox and let the user input an INTEGER manually instead of a Dropdown menu?

Thanks a lot in advance :)

My Jsp Menu is like this:

<body> <form action="AddPoints"> <table width="408" border="0"> <tr> <td width="402"><h3 align="center">Enter Points:</h3> <h3 align="center"> <label for="Points"></label> <select name="Points" size="1" id="Points"> <option value="5" selected>5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> </select> <br/> </h3> <h3 align="center"><strong></strong> <input type="submit" name="AddPoints" id="AddPoints" value="Add Points"> </h3></td> </tr> </table> </form> </body>

Also I am wondering if the value at this line: <option value="25">25</option> is the real value that my servlet can capture?

Sorry if i have so many questions... :)

最满意答案

int selectedItem; if(request.getParameter("Points")!=null) { selectedItem=Integer.ParseInt(request.getParameter("Points")); } int selectedItem; if(request.getParameter("Points")!=null) { selectedItem=Integer.ParseInt(request.getParameter("Points")); }

更多推荐

value,菜单,电脑培训,计算机培训,IT培训"/> <meta name="description" co

本文发布于:2023-08-07 02:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:菜单中   DropDown   jsp   menu   capture

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!