• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ServletOutputStream

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys!

Can anybody please help me to write and test a small ServletOutputStream example.

Thank You. :roll:
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mukunthan Shanmuganathan,

Welcome to the ranch.

What type of help are you looking for?
It's a little odd to want to write a ServletOutputStream program without first having a problem to solve, unless it's a homework assignment.

Is this a homework assignment?
 
Mukunthan Shanmuganathan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thank you!

This what I did.

package com.mypack;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class MyFirstServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

byte[] bytearr = new byte[6];

for(int i=0 ; i < bytearr.length ; i++) {
bytearr[i] =(byte) i;
}

ServletOutputStream out = response.getOutputStream();

for(int j=0 ; j < bytearr.length ; j++) {
out.write(bytearr[j]);
}

}

}

When I deploy and run I get a blank screen. Why?

Since I'm new to WCD, kind enough to bear me.

Thank You.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of things that you are missing.

Firstly, when you send something to the browser, it needs to be something that the browse is able to display. You're code responds with 6 bytes of data, but there is a good chance you just managed to confuse the browser

The second thing is called a 'mime type', which is like a hint about what the content is. Browsers can use other tricks to find the data type, but it is better if you pass that information yourself.

 
Mukunthan Shanmuganathan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ben Souther, David O'Meara!

I've got it.

Thank you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic