简体   繁体   中英

send parameter between jsp and servlet

I need to send parameters from jsp to servlet but to update only one row not all the rows generated by servlet. Can you help me with this? My code for the servlet is:

public class ExcelTest extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //processRequest(request, response);

        response.setContentType("text/html");

        PrintWriter out = response.getWriter();

        //out.println(request.getParameter("customerName"));
        for (int i = 0; i < 250; i++){
            out.println("<input + id = " + i + " type=\"text\" value = " + request.getParameter("customerName") + ">");
            request.setAttribute("vvv", i);
            out.println("<a href=\"http://localhost:8079/TesteExcel/createparameters.jsp\">Visit</a>");
            out.println("<div>");            
            for (int j = 0; j < 10; j++){                
                out.print("<div id = " + i + "" + j + " style=\"width:100px; float:left\">" + i + " - " + j +"</div>");
            }
            out.println("</br>");
            out.println("</div>");
        }
    }
}

and for the jsp is:

<form name="excel" action="ExcelTest" method="post">
            <input type="text" name="customerName">
            <input type="text" name="customerCUI">
            <input type=submit value="click me">

</form>

Thank you, Coco

Try this

         String custName = request.getParameter("customerName");
            for (int i = 0; i < 250; i++){
                if(i!=0)
                    custName="";
                out.println("<input + id = " + i + " type=\"text\" value = " + custName + ">");
                request.setAttribute("vvv", i);
                out.println("<a href=\"http://localhost:8079/TesteExcel/createparameters.jsp\">Visit</a>");
                out.println("<div>");            
                for (int j = 0; j < 10; j++){                
                    out.print("<div id = " + i + "" + j + " style=\"width:100px; float:left\">" + i + " - " + j +"</div>");
                }
                out.println("</br>");
                out.println("</div>");
            }

For first iteration only,it will take customer name .

Here I am assuming that you need that input tag in each iteration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM