当我传递参数时,JSP页面给我空值

时间:2014-05-27 07:34:26

标签: java html jsp

我想显示我的图片名称

这是从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,这是代码中的问题。

1 个答案:

答案 0 :(得分:0)

使用:

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