JamalU JamalU - 6 days ago 7
Java Question

Sending boolean as requst 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
.

Thanks in Advance.

Answer

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

boolean hasCreatePermission= Boolean.parseBoolean(request.getParameter("hasCreatePermission")); 
Comments