我不知道如何检查我的参数是否为空。怎么办?
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/