out.print()不能使用jsp方法

时间:2017-11-16 11:05:25

标签: java jsp methods

out对象显示错误,如找不到符号。试过很多方法来修复错误。但它仍然显示错误

   <%@ page import="java.sql.*" %>
    <%!
        void loadBuilding() throws Exception
        {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost/crm","root","");
                Statement st = con.createStatement() ;
                ResultSet rs =st.executeQuery("select name from building where 1") ;
                rs.last();
                int count=rs.getRow();
                if(count>0)
                {
                    rs.beforeFirst();
                    while(rs.next())
                    {
                        out.print("<script>passName('"+rs.getString(1)+"');</script>");
                    }
                }
                else
                {
                    out.print("No Buildings Added Yet");
                }
        }
        %>

        <%
        loadBuilding();

        %>

out.print() shows error

1 个答案:

答案 0 :(得分:1)

根据您在out上调用的方法,您可能需要outPrintWriter,其输出将写入由此生成的响应的OutputStream JSP。

添加:

PrintWriter out = new PrintWriter (response.getOutputStream ());