Topic: 请教:如何在jsp页面里执行存放在数据库里的一段jsp代码??

  Print this page

1.请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? Copy to clipboard
Posted by: xuanhai
Posted on: 2002-12-17 13:16

我在数据库里放置了几段jsp代码(是含有<%.....%>)
我在另一个jsp页面要用到某一段代码,我从数据库里取出后
用out.print()输出,但是并没有转换为html,
有什么办法吗????

2.你这个问题比较奇怪哦 [Re: xuanhai] Copy to clipboard
Posted by: rainman
Posted on: 2002-12-17 13:32

jsp必须编译成class来执行,所以你这种方式无效。
用XSL或BCEL来解决吧。

3.Re:请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? [Re: xuanhai] Copy to clipboard
Posted by: xuanhai
Posted on: 2002-12-17 13:41

我有一个想法,想法而已!!:)
在编译时刻就连接数据库取出数据,然后再编译为.java,能行吗?

4.Re:请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? [Re: xuanhai] Copy to clipboard
Posted by: floater
Posted on: 2002-12-18 01:31

xuanhai wrote:
我在数据库里放置了几段jsp代码(是含有<%.....%>)
我在另一个jsp页面要用到某一段代码,我从数据库里取出后
用out.print()输出,但是并没有转换为html,
有什么办法吗????


First, like rainman said, it's not working. Secondly, don't we think this is a bad design? You are mixing java code with database! What if there is a change of either one of them in the future, say, you change your database from sybase to oracle, then your presentation layer will be broken. And if, for god's sake say, there is a java#(hehe, I take the liberty), suppose it's fantastic, superior to java and c#, you want to use it, then you have to change db.

Whenever possible, don't go down this path.(well, if for job security, that's a different story, Smile)

5.Exactlly! [Re: xuanhai] Copy to clipboard
Posted by: rainman
Posted on: 2002-12-18 01:51

要编译成class

6.Re:请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? [Re: floater] Copy to clipboard
Posted by: snowbug
Posted on: 2002-12-18 02:55

floater wrote:
First, like rainman said, it's ....


Agree!

To go back to answer the original question, one way to solve it is to use a "code generator". Each time you change the code that you stored in the database, call this "code generator" to create the updated jsp files and overwrites the old one.

Still, it is not logically sound to store the code in the database because the code represent "business logic" rather than data.

7.Re:请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? [Re: xuanhai] Copy to clipboard
Posted by: xuanhai
Posted on: 2002-12-19 11:28

有人告诉我用out.print(out.print())可以实现。但是我没有成功。
不知道是我没有做对,还是这个方法也根本不行!!!!

8.Re:请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? [Re: xuanhai] Copy to clipboard
Posted by: xjimmy
Posted on: 2002-12-19 13:11

这种方法基本可以肯定是不行的。
Java是编译后执行的,编译器不可能帮你从数据库中取出代码。
提出这样的问题因该是没有理解编译执行和解释执行的区别。
最重要的还不是这一点,而是像某人说的,这是一个bad design.

9.Re:请教:如何在jsp页面里执行存放在数据库里的一段jsp代码?? [Re: xuanhai] Copy to clipboard
Posted by: fat32
Posted on: 2002-12-19 17:44

有两种方法可以实现:
第一种:
调用应用程序服务器(比如WebSphere)的JSPParser类来解释,编译你的JSP代码,这种方法比较复杂,而且会使你的代码没有通用性,因为每种应用程序服务器的JSPParser都不同.

第二种: 这种方法很简单,呵呵:
1)从数据库中取出JSP代码,动态创建文件jsp文件
2)然后通过重定向或者response.sendRedirect()或者RequestDispatcher().forward将请求定想到这个jsp文件.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923