JSP中用户定义函数内的HTML标记,不使用out.println

时间:2012-06-01 05:52:52

标签: java jsp

我在JSP中有一个包含html标签和简单语句的方法。我在每个陈述之前都做过感叹号(!)。在服务器中部署jsp之后,我检查了jsp文件并发现通过执行此操作(使用'!'符号),我的所有语句都保留在同一个函数中,html进入jsp的Service()方法,根本不需要。 out.println()是一个选项,但我不想使用out.println()方法来编写html,因为它等同于在servlet中编写html。

部署后的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
}

}

有没有其他选择做同样的事情?

感谢您的帮助

0 个答案:

没有答案