How to get the username of user who logged into Jasper Server?

喜欢而已 提交于 2019-12-11 09:23:15

问题


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!!


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/22323614/how-to-get-the-username-of-user-who-logged-into-jasper-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!