I have a jasper report with a field $F{fupgrade_package_name}
so when I run my query upgrade_package_name is set to http://www.something.com/file.exe
I want to only display file.exe in the report and not the full URL.
How is this done?
Thanks
You can use this expression:
<parameter name="url" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["http://www.something.com/file.exe"]]></defaultValueExpression>
</parameter>
<textField>
<reportElement x="122" y="28" width="100" height="20"/>
<textElement/>
<textFieldExpression>
<![CDATA[$P{url}.contains("/") ? $P{url}.split("/")[$P{url}.split("/").length-1] : $P{url}]]></textFieldExpression>
</textField>
The result will be:
file.exe
And for the url = "just_file_wout_url.txt"
the result will be:
just_file_wout_url.txt
For your case the expression will be:
$F{fupgrade_package_name}.contains("/") ? $F{fupgrade_package_name}.split("/")[$F{fupgrade_package_name}.split("/").length-1] : $F{fupgrade_package_name}
您可以像处理字符串一样处理$F{fupgrade_package_name}.split(regex)[0]
,可以使用正则表达式。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.