从jsp获取数据到Servlet

时间:2015-11-26 20:48:02

标签: java jsp jstl servlet-3.0

我的select标签成功填充了我想要的字符串,但是当我点击提交并尝试获取select标记的值时,它返回null。

index.jsp 表单

<form action="ServletMain" method="post" enctype="multipart/form-data">
        <select id="file_from_server" name="file_from_server">
            <c:forEach var="file" items="${files}">
                <option><c:out value="${file.getName()}" /></option>
            </c:forEach>
        </select>
        <input type="submit">
    </form>

ServletMain doPost方法

protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String fileFromServer = request.getParameter("file_from_server");

        PrintWriter pw = response.getWriter();
        pw.append(fileFromServer);
    }

0 个答案:

没有答案