2015-11-17 77 views
0

我需要將參數從jsp發送到servlet,但只更新一行而不是所有由servlet生成的行。 你能幫我嗎? 我的servlet代碼是:在jsp和servlet之間發送參數

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>"); 
     } 
    } 
} 

,併爲JSP是:

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

</form> 

謝謝 可可

+0

信息不完整。請提供更多信息,以便我們提供幫助。你想發送什麼參數?你是否嘗試將它存儲在會話中? –

+0

我試圖從jsp頁面將「customerName」參數發送到「out.println(」「);」來自servlet的行。問題是它會在每一行發送。 – coco

回答

0

試試這個

  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>"); 
      } 

對於第一次迭代只,它將需要customer name

這裏我假設你需要在每次迭代中使用input標記。

+0

是的,我需要每次迭代中的輸入標籤。這個想法是,當我按下「訪問」鏈接時,更改僅適用於該鏈接,而不適用於所有輸入標籤。 – coco

+0

你想訪問鏈接一次? –

+0

不,我需要從jsp只更新一個標籤而不是所有的輸入標籤。我想要更新的標籤是帶有我選擇的鏈接的標籤。在我從servlet生成html的那一刻,我改變了所有的標籤 – coco