gothiora
gothiora

Reputation: 41

Check if request.getParameter is null using JPS

I don't know how to check if my parameter is null. How?

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

My code not working:

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

AND

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

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

How can I check it?

Upvotes: 2

Views: 524

Answers (2)

Gurkan Yesilyurt
Gurkan Yesilyurt

Reputation: 2675

First, check that param exists.

For example;

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

Upvotes: 1

Alexey Malev
Alexey Malev

Reputation: 6533

Try this:

<% if (request.getParameter("p_r") == null) {
       //it is null. do null-handling
   }
%>

Upvotes: 0

Related Questions