在tomcat 5.x上运行的jsp页面中getParameter文本字段返回null

null return on getParameter text field in jsp page running on tomcat 5.x

本文关键字:getParameter 文本 字段 null 返回 jsp tomcat 运行      更新时间:2023-09-26

我得到一个奇怪的错误页面不断波动之间的nullpointerexception到实际执行的每个表单提交。我正在编写一个简单的jsp页面,并在tomcat 5上运行它。x服务器。我从一个表单的文本字段和处理表单提交它的数据。这是我正在尝试的代码:

form id="mainForm" method=POST action="index.jsp">
<input type="text" name="reportName" size=20> 

<a class="btnBlue btnBlueRight" href="#" onclick="document.getElementById('mainForm').submit();" > 
            <% 
            if(request.getParameter("reportName")!=null){
            //do things
            else
            //print message
            %>

对于此代码,地址栏中的页面地址是localhost:8080/#或localhost:8080/index.jsp对于每个表单提交。我是jsp新手,所以无法解决这个问题。

这是因为reportName在第一次加载页面时没有设置任何位置!例如,尝试导航

localhost: 8080/index . jsp ?reportName =所有的