将Dojo表单中的表值传递给Java servlet

时间:2011-06-13 08:17:31

标签: forms servlets html-table dojo http-post

我希望将参数值从我的dojo表单传递给Java servlet。我能够连接到servlet,但我无法提取表单的参数。我试图在我的servlet中检索我的“appid”的值。请帮忙!

Dojo表单(form.jsp)

<div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data"
    action="UpdateServlet" method="POST">         
    <table id="newTable">
        <tbody><tr>
               <td>ID:</td><td><span id="appid" title="ID"><%=app.getId()%></span></td>
               </tr>
        </tbody>
        </table>
        <button dojoType="dijit.form.Button" type="submit">
         OK
         </button>

</div>

UpdateServlet.java

public class UpdateServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {

        String appId = (String) request.getParameter("appid");
        System.out.println("App id is " + appId);
        //Appid is null, unable to extract value
        response.sendRedirect("index.jsp");
    } finally { 
        out.close();
    }
} 

}

1 个答案:

答案 0 :(得分:0)

提交表单时,不会自动提交表格的值。您需要使用某种表单控件。在你的情况下,我认为你可以添加一个隐藏的输入控件来做到这一点,如下所示:

<input type="hidden" name="appid" value="<%=app.getId()%>">