2014-01-13 64 views
0

您好我是jsp的新手,我正在做一些练习,第一个是通过jspInit()方法输出数据,并且我还没有能够使它工作uu我知道这太愚蠢了)。一切正常,我jsp页面上罚款,直到我写这样的方法:通过jspInit()方法输出数据

<%! 
public void jspInit() 
{ 
    out.println("Inicializando el servlet de bienvenida"); 
} %> 

,我从服务器上得到的消息是“出解决不了”。

是否有任何其他方法可以使此方法打印一些输出数据?

我也想知道为什么我的代码不工作=(

+0

你认为'out'是指什么?为什么你这么想? –

回答

0

如果你真的需要输出打印,您可以使用System.our.println()

<%! 
public void jspInit() 
{ 
    System.out.println("Inicializando el servlet de bienvenida"); 
} %> 

隐对象是不是这个原因在jspInit() or jspDestroy()方法中可用。这意味着隐式对象仅在_jspService()方法中可用。隐式对象是Service Method中的局部变量。因此,这些方法在此方法外不可访问。

public void _jspService(HttpServletRequest request, HttpServletResponse response) 
     throws java.io.IOException, ServletException { 

    JspFactory _jspxFactory = null; 
    PageContext pageContext = null; 
    HttpSession session = null; 
    ServletContext application = null; 
    ServletConfig config = null; 
    JspWriter out = null; 
    Object page = this; 
    JspWriter _jspx_out = null; 

    //other code here 
} 
+0

现在我的代码没有错误,但是我想用语句'System.out.println(“Inicializando el servlet de bienvenida”)打印的消息;' ( – user3191248

+0

是的,System.out.println()将打印到控制台 –

+0

我知道,但练习的目的是打印一些输出到浏览器,现在的问题是:是有可能通过jspInit方法来完成,还是只能用来执行其他任务,比如打开数据库连接? – user3191248