Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet not setting status in Response  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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);
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!