开发者

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

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 开发者_JS百科same like how i can do it in Servlet??


In servlets you can check using getParameter method of Request Object

if(Request.getParameter("Submit")!=null)
{
     ...
     ...
}


Another (in my sense more expressive) construct would be

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

as shown here


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.
}


if (request.getParameter("paramname") != "")) { 
    // Parameter is set.
}

May solve your issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜