在提供空值​​的提交按钮上的request.getParameter [英] request.getParameter on a submit button giving null value

查看:111
本文介绍了在提供空值​​的提交按钮上的request.getParameter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击生成PDF/生成Excel提交"按钮时,它请求Servlet FileUpload 进行处理.现在,当我尝试获取按下的提交按钮的值时,它给我的值为 null .我想知道为什么会这样吗?

On click of Generate PDF/Generate Excel submit button it is requesting the servlet FileUpload to do the processing.Now when I am trying to get the value of the submit button that i have pressed,it is giving me the value as null.I wonder why is it happening?

这是我的HTML代码:

Here is my HTML code:

<form action="FileUpload" method="post" enctype="multipart/form-data">
<input type="file" id="filename" name="filename"><br>
<input type="button" value="Upload"><br>
<input type="submit"  value= "Generate PDF" name="pdf">
<input type = "submit" value="Generate Excel" name="xls">
</form>

这是我的servlet代码:

This is my servlet code:

String generatePDF= request.getParameter("pdf");//null
if(generatePDF.equals("Generate PDF"))//Giving NullPointerException at this step
{
  System.out.println("generatePDF button pressed");
}

推荐答案

据我所知,问题似乎出在您已将多部分请求发送到服务器这一事实.此问题中的第二个答案似乎可以解决您的问题.本质上,您必须使用Apache Commons FileUpload包中FileItem类提供的方法.或者,如建议的此处,您可能必须使用HttpServletRequest类的getPart()方法

As far as I can see the problem seems to be with the fact that you have a multipart request being sent to the server. The second answer in this question seems to have the solution to your problem. Essentially, you have to use the methods provided by FileItem class in the Apache Commons FileUpload package. Or, as suggested here, you may have to use the getPart() method of the HttpServletRequest class.

这篇关于在提供空值​​的提交按钮上的request.getParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆