Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to out.print in a JSP function..  RSS feed

 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently I pass object variable "Writer out" to my JSP function via passing "out" from the main body of my file.
However, when you close the JSP via %> <% tags within the function to type some standard HTML that's easier to type instead of out.write'ing it, it gives an error saying it can't out.print. Apparently anything you don't have within <% .. %> is defaulting out.print.
Does anyone know if there is a way to either pass an out.print variable to the function so it can use it's default out.print.. OR make it default out.write somehow.
[ February 25, 2003: Message edited by: Jeff Grant ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand correctly, your mistake is that the variable is 'out' and not 'out.write'
You'd have to drop some same code, but this should work:

Although personally I believe it would be better to have an external function that returned a String and <%=include the String%> in your JSP.
Dave
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it was a simple function, then yes, I would return a simple String.
However, it is not a simple little function that parses or does some math. This function does much more. What I want to do is this...

Of course my function that I would like to do this with is not THAT simple, but there is a sample function with a sample output. I have figured out how to out.write "'s by going + '"' to the out.write string... but that is a huge pain.
I want to be able to close the %> <% tags and output some text. However, it defautls to be an out.print (which is unresolved) instead of out.write and I can't figure out how to change it or how to pass an out.print capable variable to my function since that is what it obviously defaults to.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Something like this should still work for you.
Call it in your JSP as:

I just include the DataThingy to show you can (and need to) pass other data along with it. DON'T put the data in instance variables! That is a big no-no.
As you should know, the out variable is already declared as a part of the implicit JSP variables. You don't need to declare it yourself.
Dave
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:

Something like this should still work for you.
Call it in your JSP as:

I just include the DataThingy to show you can (and need to) pass other data along with it. DON'T put the data in instance variables! That is a big no-no.
As you should know, the out variable is already declared as a part of the implicit JSP variables. You don't need to declare it yourself.

Actually, for function calls, it does not automatically pass the "out" variable. That is why I pass it.
And thanks for the info on the /" or "\ or whichever it was... I will use that from now on. Much easier than having to end the quotes to enter a " as a character '"'.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!