Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending boolean as request parameter

In my web application I have a link - "Create New User". From the jsp I am sending some request to the server like -

<div style="float:right" class="view">
 <a href="/some/url/createUserMVC.do?hasCreatePermission=${user.hasPermission['createUser']}">Create New User</a>
</div>  

Here user.hasPermission[] is an array of boolean. If the current user (that is user ) has the permission(that is 'createUser') to create an new user than it returns true.

Now from my controller I am trying to get the value from the request parameter, like -

request.getParameter("hasCreatePermission"); 

But the problem is request.getParameter() returns a String. So how can I get the boolean value from the parameter. There is no overloaded version of request.getParameter() method for boolean.

like image 899
JamalU Avatar asked Mar 25 '15 18:03

JamalU


2 Answers

I don't think it is possible. Request is always String content. But you can do

boolean hasCreatePermission= Boolean.parseBoolean(request.getParameter("hasCreatePermission")); 
like image 127
singhakash Avatar answered Oct 29 '22 02:10

singhakash


If you are sure it's a boolean you can use

boolean value = Boolean.valueOf(yourStringValue)
like image 42
Ria Avatar answered Oct 29 '22 02:10

Ria