How to get the username of user who logged into Ja

2019-07-25 13:01发布

Please tell me if there is any method through which I can get the user name of the user who logged into the Jasper Server, and that name could be displayed in the report.

Is there any parameter which can be referred or any other work around to obtain the logged in user name or any other way to deal with the issue.

Thanks in Advance!!

2条回答
我命由我不由天
2楼-- · 2019-07-25 13:08

Try declaring a parameter with the name "LoggedInUsername" (this exact name, since it is reserverd by jasper to hold the username of the logged user).

<parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false"/>

and use it like $P{LoggedInUsername}.

Note: this will only work on the server, not in iReport.

查看更多
Evening l夕情丶
3楼-- · 2019-07-25 13:26

Open report in iReport and create a parameter with name "LoggedInUser" and class "com.jaspersoft.jasperserver.api.metadata.user.domain.User", otherwise you can copy the below XML line in XML of the report where all parameters are listed.

   <parameter name="LoggedInUser" 
        class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>

Then add a text field and then you can refer to this parameter, like:

    <textFieldExpression class="java.lang.String">
           <![CDATA[$P{LoggedInUser}.getFullName()]]></textFieldExpression>

or

    <textFieldExpression class="java.lang.String">
           <![CDATA[$P{LoggedInUser}.getUsername()]]></textFieldExpression>
查看更多
登录 后发表回答