Hi Guys,
I am new here in this community. I still did some stuff with JSP, but now I have a principle questions. Would be nice to receive some feedback...

I wanna build up a website with several JSP pages. But I don't want to place all the content into the JSP page. Well that's a common goal, separating content and structure.

What I am targeting on is referencing specific content-items in a JSP page by a key and language dependent, which can be handled via session scope. For example I have a line like this in a JSP page:
<mytag:include key="level1.sublevel4.intro.text"/>

This should load the targeting content stored in another JSP file (not simple XML) that only stores content items. For example like this:
<content-item key="level1.sublevel4.intro.text">
<language>en</language>
<content>A lot of <html:link href="..">text</html:link>...</content>
</content-item>

I not only wanna use a simple XML file for storing content, because I also wanna use JSP-TagLibs inthere, for example <html:link...> or others.

I also know about the MessageResources concept, but I doesn't think this fits my need, especially not the MessageResources_en_US.properties file idea.

Perhaps there is a very simple standard solution for this, I didn't found until know. Would be nice to receive some feedback. Thanks a lot in advance.

Best regrads from Germany.

> But I don't want to place all the content into the JSP page.
> This should load the targeting content stored in another JSP file (not simple XML)

The above two lines are contradictory; you still end up placing the content if your JSP file.

> I also know about the MessageResources concept, but I doesn't think this fits my need

Why? You can use Message bundles inside your JSP's with the fmt (format) JSTL tag library.

As far as your needs are concerned, you just need to create a JSP file which pulls the data from a message bundle (depending on a locale of course) and include it in your main JSP file. Pass in the required language(locale) to the included JSP as a parameter.

[include.jsp]

<fmt:setLocale value="${param.lang}" scope="request" />
<fmt:bundle baseName="Bundle">
<table>
  <tr>
    <td>Name</td>
    <td><fmt:message key="name" /></td>
  </tr>
  <tr>
    <td>Hello</td>
    <td><fmt:message key="hello" /></td>
  </tr>
  <!-- and so on -->
</table>
</fmt:bundle>
[Bundle_en.properties]

name=YourName
hello=Hello-in-English
[main.jsp]

<jsp:include page="include.jsp">
  <jsp:param name="lang" value="some-locale-like-en" />
</jsp:include>

Google for these terms for more explanation and read the J2EE 5 tutorial. for more on tags.

Hello,
sorry for late reply, but I was on working out a solution for this ;-)
And thank you very much for your feedback! This helped my on establishing nice results.
I would like to separate content and structure of a page, but both files should be jsp files.
So in principle the idea of include is good enough, but I don't like it because of the complicated syntax.
I solved this issue, with using "Tag Files", to wrap some JSP code and giving me a nice and clear API for storing content and for loading it via keys in the final page.

The first code example shows how to store the content snippets.

[file for content storage]
<my:content-provider-init keyprefix="level1.level2">
    
    <my:content-provider-element key="intro" language="en">
        This is <i>english</i> content.
    </my:content-provider-element>    
    <my:content-provider-element key="intro" language="de">
        Dies ist deutscher Inhalt.
    </my:content-provider-element>         
    
</my:content-provider-init>

The second example shows how to call these above defined code snippets.

[requested JSP page]

<%@ taglib tagdir="/WEB-INF/tags/my" prefix="my" %>
<html>
<body>
        <my:content-loader-init keyprefix="level1.level2"/>
        <br/>
        <my:content-loader key="intro"/>
        <br/>
        <my:content-loader key="paragraph1"/>
</body>
</html>

Good thing you found a solution to your problem but I still believe locale specific content needs to be moved to separate message bundles instead of being embedded in JSP's; but then again it might be a limitation imposed by your design.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.