jsp - How to get the select box value from jsp to another servlet?
问题描述
Here is my jsp
<form action = "first" > <!-- first servlet -->
<select name="loginAs">
<option>Fan</option>
<option>Club Member</option>
<option>Admin</option>
</select>
</form>
Here is my servlet :
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String c = req.getParameter("loginAs");
}
but it is still showing as null when I use c
解决方案
您应该为您的选项添加value
属性:
<form action="first" > <!-- first servlet -->
<select name="loginAs">
<option value="Fan">Fan</option>
<option value="ClubMember">Club Member</option>
<option value="Admin">Admin</option>
</select>
</form>
推荐阅读
- python - 简单的问题,但我已经堆积了一点
- rust - 使用 Tokio 生成非静态未来
- c++ - 调用模板函子的更简单的语法
- java - 如何在 Java 中检查 ObjectInputStream 是否为空?
- javascript - 从全局路径 nodejs 查找文件夹是否存在
- c# - Linux 上的 ASP .NET + Docker 抛出 system.io.filenotfoundexception: 找不到文件
- c++ - 如何在 C++ 中正确读取二进制文件中的数据直到最后一个数据?
- html - 在 Coldfusion 中使用 Font Awesome Unicode
- ios - 实例成员不能用于“AppDelegate”类型
- list - 如何从 Robot 框架中的整数项列表中找到最大的数字?