You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Shanta B <B....@siemens.com> on 2003/04/23 12:08:53 UTC

Http code 302 send RedirectProblem

Hi
    I am getting Http302 in my apache access log ....

 This is the sample  servlet call to download servlet.This code is
 working at ourside,but it is not working at our client.We are using
servlet2.3 and tomcat4.1.18 servlet container.

pl find my download servlet and otherservlet which calls download servlet




import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import sun.misc.BASE64Decoder;
public class DownloadServlet extends MsServlet
{
    public String getServletInfo(){
        return "This servlet changes the message content type and send it to
the client.";
    }

    public void doPost(HttpServletRequest req, HttpServletResponse rsp)
	throws IOException
    {
        if (PrimitiveWml.checkAndPanicWmlClient(req, rsp))
            return;
        SieMsSession session =
	    SieMsSession.getOrCreateHtmlSession(req.getSession().getId());
        String contentType = req.getParameter("contentType");
        String fileName = req.getParameter("fileName");
        setResponseHeader(rsp, contentType, fileName);
        printOutput(session, req, rsp);
    }

    public void setResponseHeader(HttpServletResponse rsp, String
contentType,
				  String fileName) {

        if (fileName == null || fileName.equals("")) {
            fileName = "document.txt";
        }
        if (contentType == null || contentType.equals("")) {
	    rsp.setContentType("text/html; charset=iso-8859-1");
        }
        rsp.setHeader("Content-disposition", "attachment; filename=\"" +
fileName + "\"");
        rsp.setContentType(contentType);
    }

    private void printOutput(SieMsSession s, HttpServletRequest req,
HttpServletResponse rsp)
    {
        try
        {
            PrintWriter out =rsp.getWriter();
            String messageToDownload = (String)s.at("toDownload");
            if (messageToDownload != null)
            {
                out.print(messageToDownload);
            }
            else
            {
                out.print("<!-- EMPTY DOWNLOAD -->\r\n");
            }
            out.flush();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}


Call to DownLoadServlet
------------------------
try
{
  String contentType="application/vnd.ms-excel";
  s.atPut("toDownload", messageToDownload);
  String shref = s.attachSessidToUrl("Download?contentType="
         + contentType+"&fileName="+fileName);
  rsp.setHeader("asdasd", "asdasdasdasdasdasd");
  rsp.sendRedirect(shref);
  s.logDebug(getClass(),"...redirected");
} 
catch (Exception e)
{
         rsp.setContentType("text/html; charset=iso-8859-1");  
         showError(e.getMessage());
}



-----Original Message-----
From: Shanta B 
Sent: Tuesday, April 22, 2003 2:55 PM
To: 'Tomcat Users List'
Subject: RE: send RedirectProblem


Hi 
    I am not getting displayed the page where it shows that wouldlike to
save or download file ...but in my logs i am seeing  ...redirected as a
message ...

try {
>  s.atPut("toDownload", messageToDownload);
>  String shref = s.attachSessidToUrl("Download?contentType="
>         + contentType+"&fileName="+fileName);
>  rsp.setHeader("asdasd", "asdasdasdasdasdasd");
>  rsp.sendRedirect(shref);
>  s.logDebug(getClass(),"...redirected");
>     } 
> catch (Exception e)
> {
>         rsp.setContentType("text/html; charset=iso-8859-1");  
>         showError(e.getMessage());
>     }




-----Original Message-----
From: Tim Funk [mailto:funkman@joedog.org]
Sent: Tuesday, April 22, 2003 2:52 PM
To: Tomcat Users List
Subject: Re: send RedirectProblem


304 is not an error. More information about what a 304 is:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5

-Tim

Shanta B wrote:
> Hi
>   I am facing some pecular problem at my client side.I have a servlet
> which is making redirecting to other servlet(named download
> servlet).This redirect occurs when you are downloading  any file from
> server .
> 
> This is the sample  servlet call to download servlet.This code is
> working at ourside,but it is not working at our client.We are getting
> 304 error.We are using servlet2.3 and tomcat4.1.18 servlet container.
> 
> 
> 
> try {
>  s.atPut("toDownload", messageToDownload);
>  String shref = s.attachSessidToUrl("Download?contentType="
>         + contentType+"&fileName="+fileName);
>  rsp.setHeader("asdasd", "asdasdasdasdasdasd");
>  rsp.sendRedirect(shref);
>  s.logDebug(getClass(),"...redirected");
>     } 
> catch (Exception e)
> {
>         rsp.setContentType("text/html; charset=iso-8859-1");  
>         showError(e.getMessage());
>     }
> 
> Its not throwing any error ,but still i can see (),"...redirected in
> my catalina.out ...Can any body has some idea.I would like to know
> that is there
> any port conflicts at serverside. Client is using https communication.....
> 
> Thanks in Advance
> Shanta.B
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org