Fog Creek Software
Discussion Board

java/C# question

What's the equivalent of Response.Write("foobar"); in jsp?

Wednesday, January 14, 2004

Wednesday, January 14, 2004

According to that document, out.print() is what I'm looking for.  But when I try to compile that line, the compiler gives me this error:
cannot resolve symbol
symbol : variable out

Wednesday, January 14, 2004

<% out.print("Foo"); %> should, indeed, act like Response.Write("Foo"). I just tested it. If you are getting errors, something else is wrong.

When you say compile, do you mean hit the page in the browser?

Matthew Christensen
Wednesday, January 14, 2004

JSP pages are converted to servlet source code then compiled the first time they are requested from a browser.

What that means is that all static text within a jsp page is rendered into out.print("static text here"); statements automatically.

Writing out.print(""); explicitly within a scriptlet (That's Java code between the <% %> tags) should also work.


Avrom Finkelstein
Wednesday, January 14, 2004

I have a .jsp that instantiates an object defined in a .java file.  I would like to put code in the .java file that will write text in the browser window for debugging purposes.

Wednesday, January 14, 2004


The predefined JSP objects, (out, application, session, request, and response), are all local variables defined in the _jspService() method. If you want to use them in another class (or in a method defined in a JSP declaration), then you have to pass the object as an argument to the method like this:

<% CustomObj myObj = new CustomObj();
      myObj.doThing(out); // pass predefined object

In you CustomObj class, your method would look like this:

public void doThing(JspWriter out) { ... }


Thursday, January 15, 2004

How about just:


Thursday, January 15, 2004

nathan, off the top of my head, I'd create a method for the Java class that will get the error(s) as a String and then print it out in the jsp page.

<%= myObject.getErrorMessage() %>

I highly suggest that you read up on jsp so you can have a better understanding on how everything works.

Sun has a tutorial on their site. Check it out.

Avrom Finkelstein
Thursday, January 15, 2004

*  Recent Topics

*  Fog Creek Home