簡體   English   中英

當我傳遞參數時,JSP頁面給我空值

[英]JSP Page give me null value when i pass parameter

我想顯示我的圖像名稱

這是從demo.jsp到自身的簡單發布請求

<form method="post" action="demo.jsp">
<input type="hidden" id="sql" name="name" value="sql"/>
 <input type="image" src="images/icons/icon-charcoalarrow.png" alt="Submit" value="go" onClick="commentBox"><br></form>

單擊我想在顯示中顯示sql。 為此,我編寫了如下代碼:

<div class="modal fade" id="commentBox" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <span class="subheading">Updated Analysis</span><br>
                <br>

                <div class="subheading-content">
                    The issue still needs attention. Please try again by
                    choosing a different option to help resolve the matter.
                    Once satisfied with a different step(s), click "<b>Save
                    &amp; Continue</b>".
                </div><%



                    String sLabel;
                    try
                    {
                        Class.forName("com.mysql.jdbc.Driver");  
                        Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
                        Statement statement=connection.createStatement();

                    %><% 
                       String labelNames[]=request.getParameterValues("name");

                       for(String str: labelNames)
                       {
                           out.println("<br>");
                           sLabel=str;
                           out.println(sLabel);
                       }

                       connection.close();
                       out.close();
                    }

                    catch(Exception e)
                    {
                        out.println(e.getMessage());  
                    }
                    %>
            </div>
        </div>
    </div>
</div>

我得到的是null而不是sql,這是代碼中的問題。

采用 :

String labelNames=request.getParameter("name"); out.println(labelNames);

代替:

String labelNames[]=request.getParameterValues("name");

                   for(String str: labelNames)
                   {
                       out.println("<br>");
                       sLabel=str;
                       out.println(sLabel);
                   }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM