File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet not setting status in Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet not setting status in Response" Watch "Servlet not setting status in Response" New topic

Servlet not setting status in Response

Bindu Kantipudi

Joined: Nov 30, 2005
Posts: 3

I have a servlet which acts like a proxy. First when servlet gets request, It creats a socket to a reporting server (run's on 80 port) and sends a request. After getting a file from that server this servlet tries to set status and the header in HttpServletResponse. Latter it writes the data to a ServletOutputStream.

My problem is, the page is not displayed on the browser when I try to access it from webserver. If I run the application directly on test box,it is displaying the page. When I check the webserver logs it is sending a request as below.
/ActuateReportServlet?report=TransactionHistory HTTP/1.0" - -

and I am thinking it is not setting the status and so server is not displaying the page.
Please help me with this problem.

Here is the code in servlet which does

Socket socket = new Socket(host, port);
boolean b1 = socket.isConnected();
System.out.println("Socket Connection = "+b1);
PrintStream ps = new PrintStream(socket.getOutputStream());
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

String file = url.getFile();
String request = new StringBuffer("GET ").append(file).append(" HTTP/1.0\r\n\r\n").toString();
System.out.println("Print Stream = "+request);

java.util.StringTokenizer st = new java.util.StringTokenizer(br.readLine());
String resProtocol = st.nextToken();
String resStatus = st.nextToken();

int status = 500;
if (resStatus != null && !resStatus.equalsIgnoreCase("")) {
status = Integer.parseInt(resStatus);
System.out.println("resStatus int = "+status);

String line = null, name = null, value = null;
if ( status == res.SC_MOVED_TEMPORARILY ) {
while( !(line = br.readLine()).equalsIgnoreCase("") ) {
name = line.substring(0, line.indexOf(":"));
value = line.substring(line.indexOf(":") + 1, line.length());
if ( name != null && name.equalsIgnoreCase("Location") ) {
if ( MLSFormatter.isValidString( value )) {
String location = (String) System.getProperty("imaging.server");
downloadNetworkResource( req, res, location, value.trim(), null );
status = 200;

} else {
ServletOutputStream sos = res.getOutputStream();

while(!(line = br.readLine()).equalsIgnoreCase("")) {
name = line.substring(0, line.indexOf(":"));
value = line.substring(line.indexOf(":") + 1, line.length());
res.setHeader(name, value);
System.out.println("Name = "+name);
System.out.println("Value = "+value);
while ((b = != -1)
System.out.println("bytes b = "+b);
/*char c;
System.out.println("b = "+b);
for(int i=0; i<buf.length; i++){
c = (char)buf[i];
sos.write(buf, 0, b);
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Welcome to JavaRanch!

We're pleased to have you here with us in the Servlets forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here

This was the 2nd time you've been asked.
[ December 29, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Servlet not setting status in Response
It's not a secret anymore!