gpt4 book ai didi

java - 使用 JPS 检查 request.getParameter 是否为 null

转载 作者:行者123 更新时间:2023-11-30 10:52:53 24 4
gpt4 key购买 nike

我不知道如何检查我的参数是否为空。怎么办?

http://localhost:8080/msg?fn=Igor&sn=Jedna&id=2
http://localhost:8080/msg?p_r=null&fn=Igor&sn=Jedna&id=2

我的代码不工作:

<% if (request.getParameter("p_r").equals("null")) {
//do stuff with p_r
}
%>

<% if (request.getParameter("p_r").equals(null)) {
//do stuff with p_r
}
%>

org.apache.jasper.JasperException: An exception occurred processing JSP page

如何检查?

最佳答案

首先,检查参数是否存在。

例如;

    <% 
if(request.getQueryString().contains("p_r=")){
if (request.getParameter("p_r").equals("null")) {
out.print("p_r is null.");
}
}
%>

关于java - 使用 JPS 检查 request.getParameter 是否为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34241346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com