0

One JSP, which contains two forms

<div class="modal" id="modalDialog">
        <input method="post" action="newsPage">
        <input type="hidden" name="modalForm" value="modalFormPush"/>
        <input type= "text" name="title">
        <textarea cols="45" maxlength="100" onkeyup="countf()" id="text" name="content"></textarea>
        <input type="submit" value="Save" name="modalForm">
    </form>
</div>

<div class="modal" id="newsModalDialog">
    <form method="post" action="newsPage">
        <input type="hidden" name="modalForm" value="modalFormNews"/>
        <input type= "text" name="title">
        <textarea cols="45" maxlength="100" onkeyup="countf2()" id="news_text" name="content"></textarea>
        <input type="submit" value="Save" name="modalForm">
    </form>

The goal is to send data from this forms to one servlet, which inserts its to database.
From one form data values must be inserted to one table-database, from second form - to second table-database, accordingly.

protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    String modalForm = request.getParameter("modalForm");

    if ("modalFormPush".equals(modalForm)) {
        Pushdata pushdata = new Pushdata();

        pushdata.setTitle(request.getParameter("title"));
        pushdata.setContent(request.getParameter("content"));
        pushModifier.savePushdata(pushdata);
    }

    else
        if ("modalFormNews".equals(modalForm)) {
            Newsdata newsdata = new Newsdata();

            newsdata.setTitle_news(request.getParameter("title_news"));
            newsdata.setContent_news(request.getParameter("content_news"));
            newsModifier.saveNewsdata(newsdata);

        }

}

But when I try to send data from one of this forms (for example "newsModalDialog"), joint table is created. This table contains fields from two tables. And this new table is empty.

Thus, values are not inserted to database, through servlet. Thanks in advance!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

I have found a mistake.

Not

<input method="post" action="newsPage">

But

<form method="post" action="newsPage">