Outputing JSP Code from a database

  • Thread starter Henry F. Camacho Jr.
  • Start date
H

Henry F. Camacho Jr.

This might be crazy, but I would like to explore this.

It is my desire to use a servlet to serve up pages from a MySQL
database. Of course I would like to be able to use .jsp code that
would reside in the database.

Question:

How do I output that jsp code that sits in the database from a
servlet, and have it parsed by the application server?

Thanks,

HFC
 
K

KiLVaiDeN

Henry F. Camacho Jr. said:
This might be crazy, but I would like to explore this.

It is my desire to use a servlet to serve up pages from a MySQL
database. Of course I would like to be able to use .jsp code that
would reside in the database.

Question:

How do I output that jsp code that sits in the database from a
servlet, and have it parsed by the application server?

Thanks,

HFC

You could have a Java application that could write the JSP(or HTML) files
taken from database. All the structure.

I've done such thing long time ago, not in Java though, to make a website
"look like" static, by producing the pages in static HTML from the database.
Therefore the server load was quite acceptable, because nothing was
interpreted server-side anymore !

But I think what you want to do is something else, and I don't think I have
the answer for your problematic. If there is some kind of command that would
interpret JSP code "on the flow" it'd help you I believe, good luck finding
that information.

K
 
J

John C. Bollinger

Henry said:
This might be crazy, but I would like to explore this.

It is my desire to use a servlet to serve up pages from a MySQL
database. Of course I would like to be able to use .jsp code that
would reside in the database.

I don't see the "of course" part. Serving up straight HTML is one
thing, as it can be passed on directly to the client, but JSP is a
program component -- it must be compiled to a servlet, loaded, and run.
Once that was done, the generated servlet would be likely to remain
loaded, at least for a time, so the advantage of having the application
server draw the source from a database would be greatly diminished.
Question:

How do I output that jsp code that sits in the database from a
servlet, and have it parsed by the application server?

That's the wrong question. You want to ask is "How do I make an
application server serve JSPs whose source resides in a database instead
of on the filesystem?" Unless you plan to write a filesystem interface
to the database, the answer is dependent on your servlet container. For
any particular container the answer may be that you need to modify the
container.


John Bollinger
(e-mail address removed)
 
H

hfc

Question:
That's the wrong question. You want to ask is "How do I make an
application server serve JSPs whose source resides in a database instead
of on the filesystem?" Unless you plan to write a filesystem interface
to the database, the answer is dependent on your servlet container. For
any particular container the answer may be that you need to modify the
container.

That is a good question. I am running TomCat. I have a number of
objects that I wrote for perl that handle navigation. The html would
reside in a database, and my navigation handler would gather naviation
tree from the database. I can of course output html, and I can put all
kinds of tags to be processed by the servlet.

At this point I would like to convert those perl objects to Java, have
my objects handle all the navigation. Perhaps I am totally
misunderstanding JSP, and I need to start from the ground up.

HFC
 
J

John C. Bollinger

That is a good question. I am running TomCat. I have a number of
objects that I wrote for perl that handle navigation. The html would
reside in a database, and my navigation handler would gather naviation
tree from the database. I can of course output html, and I can put all
kinds of tags to be processed by the servlet.

When you write "tags to be processed by the servlet" you make me think
you are either
1) making things more difficult than they need to be, or
2) misunderstanding how servlets and JSP work.

A typical servlet front-end for a database-driven website would collect
appropriate HTML snippets from the database (based on some local logic)
and construct a complete HTML page from them, perhaps with the addition
of some HTML code chosen by the servlet itself at request time.

_Modifying_ the HTML fragments from the database at request time based
on special tags in the HTML code would be roughly equivalent to
server-side includes, but what would be the point of that when you're
already running in a servlet container? A more common paradigm would be
to write the pages as JSPs (residing locally on the server), with custom
tags and (plain) JavaBeans encapsulating the server-side logic,
including DB lookups.
At this point I would like to convert those perl objects to Java, have
my objects handle all the navigation. Perhaps I am totally
misunderstanding JSP, and I need to start from the ground up.

It seems that the natural conversion would be from your Perl objects to
JavaBeans that provide similar functionality. These would be usable
whether you write the application with JSP or only with "pure" servlets.
If you do use JSP then you might find it useful to create custom
tags around some of the beans' features, but custom tags are a nicety,
not a requirement.


I repeat an important point from an earlier post that you may have not
fully appreciated: it is *abnormal* for JSP code to be interpreted by a
servlet container in the process of handling any specific request. The
JSP code is translated to Java source for a servlet and compiled at
need, but usually such need only manifests the very first time the JSP
is accessed after its deployment (if even then).


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top