JSP is great for hosted environments (ie: shared development
environments, ISP's and large companies) where many different kinds of
people are putting pages on the servlet engine may not know much more
than HTML. Part of the reason it is so nice is that with the HTML'ish
syntax JSP is so easy to learn!
いろんなタイプの人がサーブレットエンジン上でページを用意し、
その中には HTML しか知らない人もいるような、
ホスティング環境 (つまり ISP や大企業での共有された開発環境) では、
JSP が最適です。その理由として挙げられるのは、JSP の HTML
ライクな構文を学ぶのはすごく簡単だということです。
However, if one really looks at that statement in more detail it becomes
apparent that this might not be such a good thing. Consider the
following snippet of Java code:
これについても、実際に詳細まで見ていけば、
それほど良いものでないかも知れないことが明らかになります。
以下の Java コードについて考えてみましょう。
 |
 |
 |
 |
Hashtable strings = new Hashtable();
int i=0;
while (true)
{
strings.put ("dead"+i, new StringBuffer(999999));
}
|
 |
 |
 |
 |
What this does is that it creates a Hashtable and then goes into a tight
loop. At the same time, it creates a new StringBuffer object that has a
default size of 999999. Therefore, creating what amounts to a memory
leak in the Java Virtual Machine (which all of the hosted applications
share).
ここで行っているのは、Hashtable を作成し、タイトな [無限] ループに入るというものです。
同時に、デフォルトで999999のサイズで新しい StringBuffer オブジェクトを作成します。
この結果、(ホスティングされたアプリケーションの全てで共有される) Java 仮想マシン内で
メモリリークが発生することになります。
As soon as all of the memory is gone, every single hosted application
will start to receive the dreaded "OutOfMemoryError". The reason why
this is so bad has already been explained earlier. Essentially JSP pages
themselves cannot catch OOME errors and the entire servlet engine will
suddenly become useless, all because of what amounts to a few lines of
badly written Java code.
メモリが全て消費されてしまうとすぐに、あらゆる同一ホストのアプリケーションは
恐怖の「OutOfMemoryError」を受け取るようになります。
これがなぜそれほどひどいことかについては、
最初の方ですでに説明しました。
本質的に、JSP ページ自身は OutOfMemoryError を捕捉できず、
突然サーブレットエンジン全体が使用不能になるのです。
これが全て、書き方の悪い数行の Java コードのせいなのです。
Remember, it is a bad idea to put Java code into a JSP page. Tell that
to the 14 year old kid who is being hosted on your ISP's servlet engine
who really does not care that others might be affected by these actions.
前にも述べたように、Java コードを JSP ページに入れることは考え方としては良くありません。
サーブレットエンジンが使える ISP の ホスティングサービスを使っていて、
こうした行動で他の人がどれだけ迷惑を被るかなんて全く気にしない
中学生にこのことを言ってやってください。
Velocity does not have this issue because there is no while loop in the
Velocity Template Language. The only looping construct in Velocity is a
#foreach and that loops over an array that has a finite amount of
elements. It is also possible to disable the #foreach directive and
limit the amount of recursive nesting that is possible. Note: it is
possible to modify Velocity to add a #while directive to the template
language.
Velocity ではこうした問題は起こりません。Velocity テンプレート言語 (VTL) には、
while ループは無いからです。Velocity での唯一のループ構造は、
有限の要素数の配列での #foreach ループだけです。
また、#foreach 指示子を使用不可にしたり、再帰的なネストの回数を制限することも可能です。
注: #while 指示子をテンプレート言語に追加するように、
Velocity が変更される可能性はあります。
There is nothing in JSP or Struts that prevents people from embedding
Java code in the page.
JSP や Struts では、ページに Java コードを埋め込むのを防ぐことはできません。
You make the decision.
[どちらを選ぶかは] あなたが判断してください。
[ Implementation <- Previous |
Next -> Conclusion ]
[ 実装 <- 前 |
次 -> 結論 ]