JSP に html タグと単純なステートメントを含むメソッドがあります。各ステートメントの前に感嘆符 (!) を付けました。サーバーにjspをデプロイした後、jspファイルをチェックしたところ、これを行うことで(「!」記号を使用して)、すべてのステートメントが同じ関数に残り、htmlがjspのService()メソッドに入って、まったく望ましくないことがわかりました。out.println() はそのためのオプションですが、サーブレットで html を記述するのと同等であるため、html を記述するために out.println() メソッドを使用したくありません。
デプロイ後の JSP ページ:
public final class DynamicGUI
{
// This is where the request comes in
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
JspWriter out = ...;
out.write("<html>");
out.write("<head/>");
out.write("<body>");
out.write(printelements()); // i.e. write the results of the method call
out.write("</body>");
out.write("</html>");
}
// my method
private String printelements()
{
// code stays here
but html tags goes into service(). I want them to be here
}
}
同じことを行う代替手段はありますか?
手伝ってくれてありがとう