• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Store jsp content in database

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Lets say I want save some content from a jsp page (HTML and jsp code) in a database. To make it simple I could have one field for the subject and one for the page content. But if the page content contains jsp code how is it then possible to execute that code?

/* Data in database */
INSERT INTO page ( pagecontent ) VALUES ("<b><% out.println("Hello world") %></b>");

If I want to query the jsp code from the database and execute it a jsp page, how is that possible...:

 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you want to do something this convoluted?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Not necessary (ups)... I am open for the best solutions. I know some systems store the data like subject, page content and visa versa in a XML file, which is stored in the database...

I just want to get some simple solutions on how to manage a website on the fly, i.e. be able to create and edit the content on a website like you do in a Content management system...

Sometimes your pages will use jsp code (i.e. news, debate) and if you do not prefer to hardcode the jsp code into a file stored on the webserver, but rather want to save it in the database to have easy access to make changes, then how can we solve an issue like that..

Do we use the include page action in the page content data:
<jsp:include page="codeFragment.jsp" />

- and save each code fragments into separated files?
[ August 08, 2007: Message edited by: Jeppe Fjord ]
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just separate the layout and the content. The content could be stored in a database and the layout could be jsp.

This gives your more flexibility in your design.
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I see.

But if you want to include some jsp code in the content and want to have access to the jsp code i.e. stored in the database, how would be best practice?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Why would you want to do something this convoluted?



Hello Bear Bibeault,

You write that it is convoluted, which solution would you prefer if you want to store more than static content in the database?

Thanks in advance.
[ August 12, 2007: Message edited by: Jeppe Fjord ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP has no 'eval' functionality.

There is no best practice for storing code in a database.
JSP is a templating language.
Why would you want to store code in your database?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
JSP has no 'eval' functionality.

There is no best practice for storing code in a database.
JSP is a templating language.
Why would you want to store code in your database?



I wanna store the static content in the database. Each page with a unique ID. So far so good... Let�s say I want to include some code fragments (data from database), i.e. three latest news, job offer etc., between the static content, how can I do this?

It seems that I can�t use code lines like:
<%@ include file="codeFragment.jsp" %>
<jsp:include page="codeFragment.jsp" />

- inside the static content.

But instead it seems that I can use iFrames to include files with jsp code...

Any other ideas?
[ August 12, 2007: Message edited by: Jeppe Fjord ]
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done something like this (the business users enter HTML into a DB and I retrieve it).

I did not do this in the JSP, but in the servlet (really a Struts Action but not in the JSP). You can then create a view object and place it into the request. Then on the JSP you could check to see if the attribute exists using JSTL. If it is there, then render the html (the view object will have the html as a property).
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeppe Fjord:
I wanna store the static content in the database.



Fine, static data is no problem. But JSP code is not "static content". And this is where things get rather ugly, You can't just grab JSP fragments and send them to the browser. The JSP needs to be translated and then exectued. And there is no specified means to easily make that happen with JSP fragments read from a database.

You haven't ever answered the question of why you want to store JSP rather than the data in the database.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Ku:
If it is there, then render the html (the view object will have the html as a property.



I can't see how this addresses the issue. Sending HTML to the browser is one thing. Sending JSP is another. At what point does your solution trigger the translation and execution of the JSP fragment?
[ August 12, 2007: Message edited by: Bear Bibeault ]
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You haven't ever answered the question of why you want to store JSP rather than the data in the database.



I am just looking for an easy way to let the end user be able to "include" data from database (jsp code) and edit this code as well, into the static content. Maybe there is other ways around and then I am open to here such solutions.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeppe Fjord:
I am just looking for an easy way to let the end user be able to "include" data from database (jsp code) and edit this code as well, into the static content.



Yes, but why JSP? Why not HTML or plain text? Do you really have users that prefer editing JSPs to editing text or HTML?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:


Yes, but why JSP? Why not HTML or plain text? Do you really have users that prefer editing JSPs to editing text or HTML?



Yes, I have some users, including my self, who wish to write/edit jsp code to be able get data from the database and include it as a part of the static content pages. (Is it possible to get data from the database (to query) without using JSP/java code?)

If JSP can�t be stored in the database, as I understand it can�t, then can you have some jsp files (code fragments) stored on the webserver as files in a folder, and then let the end users have access to those files. If they want to include some of the JSP files into the static content pages, they have to use iframes right? Or are there other ways around?
[ August 13, 2007: Message edited by: Jeppe Fjord ]
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic