#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    New York City
    Posts
    83
    Rep Power
    12

    I just want my JspWriter!!


    I am just wondering how I can use the JspWriter object "out" when I'm outside its default scope. I have tried to declare it as,

    JspWriter out = null;

    This does compile, but it gives me a null pointer during runtime. Is there an alternate, easier way to gain access to the writer? I've already tried several ways.
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Your question is too vague. Can you post what code you have tried and explain exactly what you are trying to do?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    New York City
    Posts
    83
    Rep Power
    12
    My question is how can I make the JspWriter "out" work as a global variable? Refer to code below.

    ---------------------------------------------------------------
    <%@page contentType="text/html"%>
    <%@ page import="java.util.*, java.sql.*, java.io.*, javax.servlet.jsp.*"%>

    <html>
    <head><title>Search | CRT</title></head>
    <body>

    <%
    //JSP WRITER WORKS INSIDE THIS SCOPE.

    String url = "jdbc:mysql:///db";
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection con = DriverManager.getConnection(url, "", "");
    Statement stmt = con.createStatement();

    String brand = request.getParameter("brand");
    String size = request.getParameter("size");

    out.println(brand);
    %>

    <%!
    public void results(String insertString, Statement stmt) throws IOException, SQLException {

    // I WANT JSPWRITER TO WORK INSIDE THIS SCOPE AS WELL.

    out.println("<TABLE border = 1>");//obviously a compiler error

    }
    %>
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, you can either pass it to your function as an argument, or you can do something like:
    Code:
    <%! JspWriter newOut = null; %>
    <% newOut = out; %>
    <%! newOut.println( "foo" ); %>

IMN logo majestic logo threadwatch logo seochat tools logo