Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the form or value is set or not?

Tags:

java

jsp

servlets

I'm creating a jsp form, once they submitted in the servlet i have to check whether the form is set or not. In PHP i use to check with the ISSET function same like how i can do it in Servlet??

like image 962
Arung Avatar asked Feb 22 '11 05:02

Arung


3 Answers

Another (in my sense more expressive) construct would be

request.getParameterMap().containsKey("paramname")

as shown here

like image 83
Jeremy S. Avatar answered Nov 08 '22 10:11

Jeremy S.


In servlets you can check using getParameter method of Request Object

if(Request.getParameter("Submit")!=null)
{
     ...
     ...
}
like image 27
Novice Avatar answered Nov 08 '22 08:11

Novice


Servlet's request.getParameter() is used to return the value of a request parameter passed as query string and posted data which is encoded in the body of request.

This method is provided by the interface ServletRequest which returns the value of a request parameter as a String, or null if the parameter does not exist. The method request.getParameter() retrieves the passed parameters and displays the value of the parameters on the browser.

Servlet equivalent of PHP isset($_REQUEST['paramname']) is

if (request.getParameter("paramname") != null) { 
    // Parameter is set.
}
like image 45
Saurabh Gokhale Avatar answered Nov 08 '22 10:11

Saurabh Gokhale