首页 > 解决方案 > 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

标签: jspservletsrequestdropdown

解决方案


您应该为您的选项添加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>

推荐阅读