| | |
Separate JSP-Page and Content
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
Google for these terms for more explanation and read the J2EE 5 tutorial. for more on tags.
> 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.
JSP Syntax (Toggle Plain Text)
[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>
JSP Syntax (Toggle Plain Text)
[Bundle_en.properties] name=YourName hello=Hello-in-English
JSP Syntax (Toggle Plain Text)
[main.jsp] <jsp:include page="include.jsp"> <jsp:param name="lang" value="some-locale-like-en" /> </jsp:include>
I don't accept change; I don't deserve to live.
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
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.
The second example shows how to call these above defined code snippets.
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.
JSP Syntax (Toggle Plain Text)
[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.
JSP Syntax (Toggle Plain Text)
[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>
![]() |
Similar Threads
- struts tutorials (Java)
- Help for learnign JSP (JSP)
- HTML - .jsp? (JSP)
- inserting code in css stylesheet (HTML and CSS)
- hover over text tips (JavaScript / DHTML / AJAX)
Other Threads in the JSP Forum
- Previous Thread: About Software / tool for JSP ??
- Next Thread: how to pass the parameters of jsp from one servlet to another
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






