2

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?

gothiora
  • 41
  • 3
  • 1
    [How to avoid Java code in JSP files](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) – Yassin Hajaj Dec 12 '15 at 15:19

2 Answers2

1

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.");
             }
        }
    %>
Gurkan Yesilyurt
  • 2,635
  • 2
  • 20
  • 21
0

Try this:

<% if (request.getParameter("p_r") == null) {
       //it is null. do null-handling
   }
%>
Alexey Malev
  • 6,408
  • 4
  • 34
  • 52