Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output of console to webpage

 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i print the console output to my webpage? I have done things like taking a variable for my output and out.println that variable, but in the case i am working now that is not an option, how can i print my console output to my jsp page?
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever your solution will be, it's not going to be thread safe. You only have one System.out but possibly multiple calls to the JSP (or servlet). The main question therefore is - why are you printing to System.out? Why not pass the response's Writer or ServletOutputStream and use that to print to? You can wrap it in a PrintWriter or PrintStream if necessary.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have this JSON array :



I want to print the result to my webpage, how can i do that?
 
Tim Holloway
Saloon Keeper
Posts: 18365
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You aren't going to do it from the console, that's for sure.

Officially, System.out and System.err don't even exist in a J2EE application environment. If you print to them, there's absolutely no guarantee as to where the output will show up. Or even if it will show up at all.

To output text to a web page, you have to obtain an HttpOutputStream from the HttpServletResponse object and write the output there. But from the sound of it, you need to study how servlets work, first.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I won't get output on webpage from console, I want the output of console to webpage. I tried this ;

out.println(DisplayInstance.result);

where in class i have done sysout for result it is giving the correct output in result but in webpage it is not giving the content I want

and also this

where i was adding the instance id and state to these objects,
and this on jsp

and still i am not getting output on webpage. What else can i do?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arushi tomar wrote:
and still i am not getting output on webpage.

What are you getting? Have you done a View Source at the browser to insect the generated HTML? Are you seeing the JSTL tags in the HTML output? If not, what is there instead?

Please try to be more complete.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All I am getting in my webpage is

Output id:
Output state:
Whatever I use I get this only.

No I haven't done view source, I don't know how to do that.
I'll search and try that also.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arushi tomar wrote:
No I haven't done view source, I don't know how to do that.
I'll search and try that also.


Just looking at the browser display, doesn't tell you much of anything.

If you are going to be working on web applications you need to know how to use basic browser tools. View Source is one of the simplest, and can be found in the browser menus. It shows you the HTML code that was sent to the browser.

Then you need to become familiar with the browser Dev Tools. See the FAQ on the HTML/JavaScript forum for more information.

Let us know what you find.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:


I was adding the JSON objects in the list list1 but I was returning list ret. All I had to do was change the return statement from return ret to return list1 and add this in my servlet:


and it works fine now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic