user972391
user972391

Reputation: 321

JSP - how to render html(or jsp) code from database

I have a jsp that is being used by multiple user groups. The requirement is that each User group wants a customized look and feel when they access the page (with a distinguishing parameter). We are proposing to allow the Users to dump the html that they need in a database table and the jsp will determine the User group and they display the corresponding html. Any pointers on how this can be done?

Example: if User group 1 access the url abc.com/xyz?param=aaa, then the jsp should display the html that is stored in the database corresponding to UserGroup1. similarly, abc.com/xyz?param=bbb should render the html stored for UserGroup2.

html for Group 1:

<html>hello, user 1 </html>

html for Group 2:

<html>hello, user 2 </html>

How does my JSP get this html code from Servlets or any other classes?

Any JSF 2.0 suggestions are also welcome.

The above example code might sound simple, but in reality the entire layout, images, borders, tables, content will be different

Upvotes: 2

Views: 1127

Answers (3)

Ashok Raj
Ashok Raj

Reputation: 454

instead of saving entire html which is not recommended as phanneman says,
save a css or css snippets . for example save in your db, the image paths for each user,
color, etc in the db for each user.
this might help by retriving the specific data for each userGroup.

Upvotes: 1

phanneman
phanneman

Reputation: 436

IMO, i would not store html in the DB. It is not where it belongs.

What you can do (in JSF 2.0) is create a 'template' page that contains basic things that you reuse on each page...header,body, footer, css, js, etc.

On this 'template' page, you can use the <ui:insert name="body"> tag to define places that each page will define.

On your pages, you use the <ui:composition template="whateverPage.xhtml"/> to define your template. Then you can insert the code you want based on whatever params using <ui:define name="body">

JSF 2 Templating with Facelets

Upvotes: 1

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93333

distinguish between users through the use of session and manage it by its API

Upvotes: 1

Related Questions