Read properties file without using Key - spring

I have a property file without Key and only content and I want to display the content of property file in jsp Page after escaping html tags. How to do this?
property file:
Here is an example of content, messages. <p>
<b>approach<b> <br>
Find out more about our website
</p>
How can I display this in jsp Page using spring? Any help?

message.properties is typically used for internationalization. Usually properties file in general is used for small value(s) and plain text.
For your case, I'd just create a separate jsp file and include it in your jsp.
<%# include file="aboutus.jsp" %>

Related

How can I add to HEAD tag using classic ASP server side code?

I have a need to add META tags inside my HEAD tag using classic ASP vbscript server side code. I am working with a system that uses a header include file (which includes the HEAD tag) on every page. I cannot change this layout. I need to add META content to the HEAD tag using server side code on my individual .asp pages.
Is this possible? If so, how? Thanks!
That's fairly straightforward.
You can add a meta tag simply by coding it into your VBScript on the server side. For instance, consider:
<%
dim metaString
metaString = "<meta name=""author"" content=""" & myName & """ />"
%>
Then in your <head> tag you can try...
<%= metaString %>
Obviously the code that defines the metaString in the first place must appear before the use of the variable.

Dandelion Datatables i18n spring resolver not working

I have recently started to integrate datatables in my spring mvc 4 + hibernate 4 + tiles 3 Project.
I want it to display header with various language support.
So I started with this link.
As per this page suggests my header shows ???key??? message.
I want to display Id in column header but it is showing ???table.header.id???.
This link says
If the key cannot be found in the bundle, the ???key??? message will be displayed in the column header.
But I have put following in datatables.properties
i18n.locale.resolver=com.github.dandelion.datatables.extras.spring3.i18n.SpringLocaleResolver
global.i18n.message.resolver=com.github.dandelion.datatables.extras.spring3.i18n.SpringMessageResolver
Also have put in global_en.properties
table.header.id=Id
I also copied same file as global.properties.. but not worked.
My jsp file contains
<datatables:table id="users" ...>
<datatables:column titleKey="table.header.id" property="userId" />
<datatables:table />
My Resource folder structure is
Where should I put table.header.id=Id??
Any help is required. Thanks in advance.
Note: I am using AJAX source + server-side processing.
About the location of your messages
You seem to be using the Spring ResourceBundleMessageSource with global as a basename. So it makes sense to put all translations of header columns in global_*.properties files.
About the ???key??? message
It turns out to be a bug introduced in the v0.10.0.
Waiting for the next version to be released, there is a workaround, but working only with DOM sources.
Here follows the steps.
1) Instead of using the titleKey column attribute, you will use the <spring:message> tag. Theorically, they do the exact same thing: lookup a resource in your configured resource bundle.
Begin by declaring the Spring taglib in your JSP:
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
2) Then you need to update the usage of the Dandelion-Datatables taglib. As a workaround, you can use the <datatables:columnHead> (docs here) tag to insert any content in a column header.
Just use it as follows:
<datatables:table id="users" ... row="user" >
...
<datatables:column>
<%-- Everything inside this tag will only appear in the header column --%>
<datatables:columnHead>
<spring:message code="table.header.id" /> <== this will appear in the column header only
</datatables:columnHead>
<%-- Everything else will appear in all cells --%>
<c:out value="${person.id}" /> <== this will appear in all column cells
</datatables:column>
...
<datatables:table />
Some observations:
You need to add the row table attribute if you need to access the object of the collection being iterated on, as it's done with the <c:out> tag of the JSTL
You need to remove the property column attribute, or the content of the <datatables:column> tag will not be evaluated
This is a lot of work for very little return - sorry for that - but waiting for the next version to be released, at least it works.
A new issue has been added.
If you are using AJAX source + server-side processing.
Make a variable first
<spring:message code="table.header.id" var="titleId" />
and added it in
<datatables:column title="${titleId}" property="userId" />
Also a fix is available here. Kindly upgrade to 0.10.1-SNAPSHOT version.
(Disclaimer required by StackOverflow: I'm the author of Dandelion)

Is it possible to add Html tags into Spring MVC3 I18N messages.properties file

Given the following MVC3 i18n use:
at a jsp file:
<s:message code="clickHere">
at message.properties file:
clickHere=Please click Here
a user's browser will display(and the word Here will be a link to http://abc.com):
Please click Here
Thanks
Did you try
<s:message code="clickHere" htmlEscape="false" />
In any case you use Thymeleaf, instead of th:text, you should use the th:utext.
Example below:
# Instead of this
<div th:text="#{message}">text to be replaced</div>
# Use this
<div th:utext="#{message}">text to be replaced</div>
You should always keep in mind that using the th:utext can cause XSS Attacks.
In the properties file, you will obviously have the following,
# In properties
message=Text to be displayed

Struts2 i18n java properties, how to show special character?

If any body else have solution on this please replay.
I'm using Struts2 and getText method to fill i18n and text tags.
For example I use:
free.text.search.label=&#269eské On-line Hledat
&#269 is a HTML code for special character č (Czech Republic). I want to use in properties file.
But in my JSP, I get : &#269eské On-line Hledat instead of české On-line Hledat
I use this to display text on my JSP:
<s:label for="searchInput" value="%{getText('free.text.search.label')}" />
So what's the error? Actually this problem i am facing for label as well for button.
Use \u010D instead of &#269
.properties
free.text.search.label=\u010Deské On-line Hledat
.jsp
<s:label key="free.text.search.label" />
Output
české On-line Hledat
How I solved it?
Just paste české On-line Hledat into .properties file in my IDE (Eclipse).
Or
See
Unicode Character 'LATIN SMALL LETTER C WITH CARON'
(Encodings > C/C++/Java source code)
A to Z Index of Unicode Characters
Unicode Character Search
Well i am not able to understand your issue properly
but few points i would like to mention here
<s:label for="searchInput" value="%{getText('free.text.search.label')}" />
use key in place of this to make this more easy to read and maintain
like
<s:label for="searchInput" key="free.text.search.label" />
also since meta tags are no longer applicable to struts2 so you can try using this
<%# page contentType="text/html;charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags" %>
May be this will help you to display special characters correctly

Exporting JSP data into excel with image

In our project we are having the requirement to export the JSP page into excel.
We cannot use Apache POI or any other open source APIs.
I came across the below mentioned simple way of doing
<%
response.setHeader("Content-Disposition",
"attachment;filename=\"mult-table.xls\"");
%> <%# page
contentType="application/vnd.ms-excel"
%> <table><tr><td> using image src to
load images </td></tr></table>
The excel is generated but the image is not shown in the excel.
In our JSP pages we are having many images which should also get exported into excel along with other data.hanks
Please let me know how to do it.
Thanks
Ravi
I use the complete URL in HTML image code, because when you download the excel, it's a text xls file, with format HTML, and the images embeddable and the absolute path, intead it can solve the image source.
like this:
<%
// Java CODE
...
String url=request.getRequestURL().toString(); // URL base page
String imageUrl=url.substring(0,url.indexOf(request.getRequestURI()))+"/images/logo.gif"; // image absolute url
...
%>
...
<!-- HTML CODE -->
...
<img src="<%=imageUrl%>" width="198" height="36" /></th>
...
As far as I know you can not insert an image in xls file, when this html xls

Resources