繁体   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