当使用enctype ="multipart/form-data"时,请求getParameter始终为null. [英] request getParameter is always null when using enctype="multipart/form-data"

查看:117
本文介绍了当使用enctype ="multipart/form-data"时,请求getParameter始终为null.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对输入的数据(例如电子邮件,密码,名称等)进行验证.但是我已经停留在验证的第一阶段,即检查用户是否未输入任何内容.

I am performing validation of inputted data such as email, password, name, etc. But I am already stuck on the first stage of validation which is to check if User entered nothing.

我已经在此处中添加了enctype="multipart/form-data",但是现在它始终可以识别null,如果成功(电子邮件不为null时),我将无法转发到登录页面.

I already added enctype="multipart/form-data" as mentioned here but now it is always recognizing email as null and I can't forward to the login page in case of success (when email is not null).

signup.jsp

signup.jsp

<form method="POST" action="signup" enctype="multipart/form-data">
    <input type="email" name="email" placeholder="tonystark@mail.com">
    <input type="submit" value="Submit">
</form>


SignUpAction.java

SignUpAction.java

public class SignUpAction implements Action {

@Override
public String handleRequest(HttpServletRequest req, HttpServletResponse resp, DAOFactory dao)
        throws ServletException, IOException {

        String email = req.getParameter("email");

        if (email == null || email.isEmpty()) {
            return "signup";   // It loads signup page again (it works)
        }

        return "login";   // It should go to the login page (it doesn't work)
    }

}

推荐答案

除非您打算使用表单上载文件,否则无需指定"multipart/form-data"的编码类型.

Unless you're planning to use your form for uploading a file, you don't need to specify the encoding type of "multipart/form-data".

<form method="POST" action="signup">
    <input type="text" name="email" placeholder="tonystark@mail.com">
     <input type="submit" value="Submit">
</form>

链接中的最后一段指出:

The last paragraph in your link states:

当使用enctype ="multipart/form-data"时,所有参数都编码在请求正文中.这意味着request.getParameter(...)然后将为所有发布的参数返回null."

"When using enctype="multipart/form-data", all parameters are encoded in the request body. That means that request.getParameter(...) will return null for all posted parameters then."

输入类型:电子邮件

Input type: email

电子邮件是html5输入类型.

Email is an html5 input type. How To Use The New Email, URL, and Telephone Input Types.

这篇关于当使用enctype ="multipart/form-data"时,请求getParameter始终为null.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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