Javascript 如何将数据从jsp页面中的表单发送到servlet?

Javascript 如何将数据从jsp页面中的表单发送到servlet?,javascript,java,html,jsp,servlets,Javascript,Java,Html,Jsp,Servlets,我有一个.jsp页面,其中显示了来自DB的一些数据(表seria[id,name,description,photo])。当用户点击带有图片和文本的区域时,如何向servlet发送id?现在无论我点击哪里,servlet都会得到seria_id=1。我的网站表单截图-> <form id="myform" action="/seria" method="post"> <%Iterator itr;%> <% LinkedList<Seria&g

我有一个.jsp页面,其中显示了来自DB的一些数据(表seria[id,name,description,photo])。当用户点击带有图片和文本的区域时,如何向servlet发送id?现在无论我点击哪里,servlet都会得到seria_id=1。我的网站表单截图->

<form id="myform" action="/seria" method="post">
    <%Iterator itr;%>
    <% LinkedList<Seria> data = (LinkedList<Seria>) request.getAttribute("data");
    Seria seria;
    for (itr=data.iterator(); itr.hasNext(); ) {
        seria = (Seria) itr.next();
    %>
    <input type="hidden" name="seria_id" value=<%=seria.getId()%>>
    <table onclick="document.getElementById('myform').submit();">
        <tr>
            <td colspan="2">
                <h3 align="center">Серия &laquo;<%=seria.getName()%>&raquo;</h3>
            </td>
        </tr>
        <tr>
            <td width="50%">
                    <img src="/img/<%=seria.getPhoto()%>" width="60%" alt="cars" hspace="20%">
            </td>
            <td>
                <%=seria.getDescription()%>
            </td>
        </tr>
    </table>
    <hr>
    <%}%>
</form>
始终打印“参数名称为'seria_id',参数值为'1'” 在github上的项目,从问题的那一刻开始。

如果您想通过

    getParameter(name);
然后您应该将值发送到URL i、 在您的案例中,行动URL为/seria

因此,将值作为

/seria?parmName1=ParmaValue1&parmName2=ParmaValue2

我明白了。而不是一种形式,现在我为每一个意甲,每一个

<%Iterator itr;%>
                            <% LinkedList<Seria> data = (LinkedList<Seria>) request.getAttribute("data");
                            Seria seria;
                            for (itr=data.iterator(); itr.hasNext(); ) {
                                seria = (Seria) itr.next();
                            %>
                            <form id="<%=seria.getId()%>" action="/seria" method="post">
                                <input type="hidden" name="seria_id" value=<%=seria.getId()%>>
                                <table onclick="document.getElementById('<%=seria.getId()%>').submit();">
                                    <tr>
                                        <td colspan="2">
                                            <h3 align="center">Серия &laquo;<%=seria.getName()%>&raquo;</h3>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="50%">
                                                <img src="/img/<%=seria.getPhoto()%>" width="60%" alt="cars" hspace="20%">
                                        </td>
                                        <td>
                                            <%=seria.getDescription()%>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                            <hr>
                            <%}%>

Сццц«&拉阔;
“width=“60%”alt=“cars”hspace=“20%”


检查roytuts.com/xchart-using-ajax-jsp-and-servlet/&roytuts.com/highchart-using-ajax-jsp-and-servlet/
/seria?parmName1=ParmaValue1&parmName2=ParmaValue2
<%Iterator itr;%>
                            <% LinkedList<Seria> data = (LinkedList<Seria>) request.getAttribute("data");
                            Seria seria;
                            for (itr=data.iterator(); itr.hasNext(); ) {
                                seria = (Seria) itr.next();
                            %>
                            <form id="<%=seria.getId()%>" action="/seria" method="post">
                                <input type="hidden" name="seria_id" value=<%=seria.getId()%>>
                                <table onclick="document.getElementById('<%=seria.getId()%>').submit();">
                                    <tr>
                                        <td colspan="2">
                                            <h3 align="center">Серия &laquo;<%=seria.getName()%>&raquo;</h3>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="50%">
                                                <img src="/img/<%=seria.getPhoto()%>" width="60%" alt="cars" hspace="20%">
                                        </td>
                                        <td>
                                            <%=seria.getDescription()%>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                            <hr>
                            <%}%>