Problem in esponse.sendRedirect()

Hi All
I am trying to write a file download, after completion of the download, I am redirecting to some other url, using response.sendRedirect
But it throws the fallowing error
Servlet.service() for servlet FileDownloadZip threw exception
java.lang.IllegalStateException
     at org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:379)
     at FileDownloadZip.doGet(FileDownloadZip.java:32)
     at FileDownloadZip.doPost(FileDownloadZip.java:319)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
     at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
     at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
     at java.lang.Thread.run(Thread.java:536)
Could any one tell me how to over come this problem?
Thank you in advance
Anbu
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
actionZipDownloadFile(zip_filename,filename, response);
response.sendredirect(�abc.html�);
private void actionZipDownloadFile(String zip_filename, String filename,HttpServletResponse response) throws IOException {
          System.out.println("I am in actionZipDownloadFile");
          System.out.println("The zip_filename=="+zip_filename);
          System.out.println("The filename=="+filename);
          File f = new File(zip_filename);
          InputStream in = null;
          try {
               jcifs.util.MimeMap mimeMap = new MimeMap();
               response.setContentType( mimeMap.getMimeType( "zip" ));
               response.setHeader( "Content-Disposition", "attachment; filename=\""+filename+"\"" );
               response.setHeader( "Content-Length", Long.toString(f.length()) );
               response.setHeader( "Accept-Ranges", "Bytes" );
               in = new FileInputStream( f);
               OutputStream outStream = response.getOutputStream();
               byte[] b2 = new byte[8192];
               int n = 0;
               while( (n = in.read(b2)) > 0 ) outStream.write(b2,0,n);
               outStream.close();
          catch (Exception e) {System.out.println("The exception is"+e);}
          if (in != null) in.close();
          if (f.exists()) f.delete();
     }

actionZipDownloadFile(zip_filename,filename, response);the response is already sent to the client.
response.sendredirect(�abc.html�);you try to redirect a response to a new resource !!
Suggestion:
redirect using javascript (client side)

Similar Messages

  • Problem in response.sendredirect()

    Hi
    I am using response.sendredirect() to forword a request to an absolute URL out side my current environment.
    but it's not working....it still tries to process the request in the same environment...
    what can be the problem???

    yes i am passing the absolue URL to the Method.
    "http://blrkec30386:9080/ececWeb/BANKAWAY?Action.Admin.Init=Y&AppSignonBankId=024"
    .

  • Problem with resonse.sendRedirect in WebSphere 5

    For some reason, when we use the HTTP-plugin for WAS5, none of the calls to response.sendRedirect in our Web application work. The result is simply a DNS error which says that the server cannot be found. However, if we run the application directly in WAS5 on port 9578 without going through the HTTP-plugin, then response.sendRedirect works fine.
    Does anyone else recognize this problem? We have to solve this soon, as one of our primary customers wants to upgrade to WAS5. Thanks!
    /Arthur

    I am presumming that you are using WebSphere 5.0.2 under OS390 or z/OS and HTTP Server 5.3. If my assumption is correct, there was a problem in the HTTP Server that was addressed when WAS 5.0.2 went past version 009. WAS 5.0.2 would generate two 502 response headers from this point on unless the HTTP server was patched. I don't have the details to hand at the moment and will repost 9/5/05 if you reply and are still having the same problem.

  • Problem with SP6 + IE + sendRedirect

    Hello,
              We've had this problem with the sendRedirect method. Under IE (all versions
              we tested), a sendRedirect would take a considerable amount of time to
              actually perform the redirection; in fact the time it took was approximately
              equal to the KeepAliveTimeout setting within the httpd.conf file of our
              front end Apache webservers (Redhat 6.2 btw). We have two Apache servers in
              front of a cluster of two Weblogic 5.1 servers (SP6).
              Now the interesting thing is when we "downgraded" the mod_wl.so file back to
              the SP5 version, the problem disappeared. Obviously i'm not happy with
              running the SP5 version of the apache/weblogic bridge due to the various
              documented issues, so am wondering if a) anyone has seen this themselves,
              (b) got it working correctly under SP6, or c) when the hell is SP7 coming
              out. ;)
              thanks
              Carl
              

              Yes, I'm having this problem too with IE, i.e. taking some amount of time until
              redirection happens. But with Netscape, the redirect is fast, i.e. normal.
              I'm using Weblogic server 5.1 with SP9 (I tested with SP8 with the same result),
              Apache 1.3.12, Redhat 6.2, IE 5.0.
              When I captured the HTTP response from the server, the content-length header showed
              533. Actually the body of the response is nothing, just a line, I think. So I
              guess IE tried to receive all 533 bytes of content until the Keep alive timed
              out, after which it followed the redirection.
              I think this is a bug in Weblogic, it shouldn't spit out 533 bytes with no content.
              Iwan
              "Joe Bella" <[email protected]> wrote:
              >
              >How can we make this work if we are using just servlets? To get around
              >the problem, I have resorted to the cheesy solution of spitting out
              >javascript redirect code. This obviously is a sub-optimal solution.
              >
              >Any other ideas for workarounds until sp7 comes out?
              >
              >thanks
              >
              >joe
              >
              >"Mike Reiche" <[email protected]> wrote:
              >>
              >>I've seen this as well. We fixed it by using a jsp:forward instead of
              >the sendRedirect.
              >>
              >>Mike Reiche
              >>
              >>"Carl Ansley" <[email protected]> wrote:
              >>>Hello,
              >>>
              >>>We've had this problem with the sendRedirect method. Under IE (all
              >versions
              >>>we tested), a sendRedirect would take a considerable amount of time
              >to
              >>>actually perform the redirection; in fact the time it took was approximately
              >>>equal to the KeepAliveTimeout setting within the httpd.conf file of
              >our
              >>>front end Apache webservers (Redhat 6.2 btw). We have two Apache servers
              >in
              >>>front of a cluster of two Weblogic 5.1 servers (SP6).
              >>>
              >>>Now the interesting thing is when we "downgraded" the mod_wl.so file
              >back to
              >>>the SP5 version, the problem disappeared. Obviously i'm not happy
              >with
              >>>running the SP5 version of the apache/weblogic bridge due to the various
              >>>documented issues, so am wondering if a) anyone has seen this themselves,
              >>>(b) got it working correctly under SP6, or c) when the hell is SP7
              >coming
              >>>out. ;)
              >>>
              >>>thanks
              >>>Carl
              >>>
              >>>
              >>
              >
              

  • Strange behaviour with response.sendRedirect

    I have a strange problem with response.sendRedirect
    --The following is part of a class that implements Filter (its main task is to check for authentication)
    The redirect method hresponse.sendRedirect doesnot work (so i had to make it a forward method using dispatcher)
    The second one however, works!!!! how could that be?
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
          throws ServletException, IOException
               HttpServletRequest h =(HttpServletRequest)request;
               HttpServletResponse hresponse = (HttpServletResponse)response;
               ServletContext application = config.getServletContext();
            Connection con = (Connection)application.getAttribute("connection");
               String username = (String)h.getSession().getAttribute("user");
               String credentials = (String)h.getSession().getAttribute("cred");
               PrintWriter out = response.getWriter();
               if (con != null)
                   try
                   Statement     stmt = con.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                         ResultSet.CONCUR_READ_ONLY);
              ResultSet rs;
                        rs = stmt.executeQuery("SELECT * FROM member WHERE username = '"+ username
                                                                                              +"' AND password ='" + credentials+ "' ");
                        if(rs.next() && rs != null)
         String path = h.getServletPath() ;
              h.getSession().setAttribute("user", username);
              h.getSession().setAttribute("cred", credentials);
              //RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(path);
    //dispatcher.forward(request,response);
              String s = hresponse.encodeURL("http://localhost:8080/support/mtext.html");
                   //out.println(s);
                   hresponse.sendRedirect(s);
                        else
         String path = h.getRequestURI();
         String query = h.getQueryString();
    //     String query_sub = query.substring(0,equalPos);
         if (!query_sub.equals("threadID"))
              out.println("error occured");
                   else
              if(query == "null")
                   query="";
              else
                   query= "?" + query;
                   hresponse.sendRedirect(hostPath + "/support/index2.jsp?"+
                   "forward="+h.getRequestURI() + query );
                   }

    Hi,
    response.sendRedirect() may throw an IOException if URL not found.So you have to write throws or try & catch.
    Ajay.

  • Issue in applying SSL selectively to Login JSP Page--Session getting lost.

    Hi,
    I am facing some issues with SSL configuration on my web site running on tomcat 5.5. I am using jdk 1.5 and form based authentication with JAAS framework.
    The SSL configuration is working perfectly when applied to complete web site, but starts giving problem when applied selectively to some JSP pages. At present I am trying to apply SSL just on the login page.
    When the login screen loads up, the URL in the browser has a protocol "*https*", as expected, but it doesn't gets changed to "*http*" once the user has successfully logged in. Why is the automatic change from https to http not ocurring?
    Also I want to know which is the default page, tomcat will direct the logged in user to, once successfully authenticated using form based login; Is there any way to change this default page to some other page. It looks like that tomcat automatically directs to index.html , once the user has been successfully authenticated, but I am not so sure. My index.html page is having 4 frames; the source of these frames are different JSP pages, which are not under SSL.
    My aim is to apply SSL just on login.jsp so that password doesn't travel in clear text. Once the user is authenticated he should see index.html and the address bar's URL should change it's protocol from https to http.
    Please, find below the code in my web.xml
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>CWA Application</web-resource-name>
    <url-pattern>/about.jsp</url-pattern>
    <url-pattern>/admin_listds.jsp</url-pattern>
    <http-method>DELETE</http-method>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
    <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
    <role-name>*</role-name>
    </auth-constraint>
    <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
    <security-constraint>
    <web-resource-collection>
    <url-pattern>/*login.jsp*</url-pattern>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
    <role-name>*</role-name>
    </auth-constraint>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
    <login-config>
    <auth-method>FORM</auth-method>
    <realm-name>CWA Application</realm-name>
    <form-login-config>
    <form-login-page>/login.jsp</form-login-page>
    <form-error-page>/login.jsp?error=true</form-error-page>
    </form-login-config>
    </login-config>
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    My login. jsp has below code:
    <form name="login" method="POST" action='<%= response.encodeURL(*"j_security_check*") %>' >
    <tr>
    <td width="100%">
    <table width="260" border="0" cellspacing="0" cellpadding="1">
    <tr>
    <td align="left" valign="top" rowspan="4"><img src="images/space.gif" width="15" height="5"></td>
    <td align="right" class="login-user" nowrap ><p>User name: </p></td>
    <td align="left" valign="top"><input maxLength="64" name="j_username" size="20"></td>
    </tr>
    <tr>
    <td align="right" nowrap class="login-user"><p>Password: </p>
    </td>
    <td align="left" valign="top">
    <input maxLength=\"64\" tabindex="2" type="password" name="j_password" size="20">
    </td>
    </tr>
    </form>
    The entries in my server.xml are following:
    <Connector port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    keystoreFile="${java.home}\lib\security\cacerts" keystorePass="changeit"
    clientAuth="false" sslProtocol="TLS" />
    I have gone through the http://forums.sun.com/thread.jspa?threadID=197150 and tried implementing it; The filter as explained in the thread does gets called but the session values are still lost.
    Please note I am using javascript to go from secure "https" to "http" once the user has successfully logged in The javascript code is as below:
    top.location.href="http://localhost:8080/qtv/index.html." ;
    If I use response.sendRedirect("http://localhost:8080/qtv/index.html") for going to non-secure mode, the index.html page does not gets loaded properly. (Please note that my index.html is made of *4 frames*, as explained earlier. This is a legacy code and frames can't be removed).
    The reason for index.html not getting loaded properly is that the Address bar URL does NOT change its URL and protocol from https (https://localhost:8443/qtv/index.html ) to "*http*" (http://localhost:8080/qtv/index.html) when esponse.sendRedirect() is used ;this is the default behaviour of response.sendRedirect(). And because the protocol in address bar is https, index.html is not able to load the other JSP's in it's frames because of cross-frame-scripting security issues (The other JSP's to be loaded in frames are are NOT secure as discussed earlier).
    Please let know if any way out.
    Thanks,
    Masaai

    Hi
    try to set the maximum interval between requests
    eg:
    session.setMaxInactiveInterval(6000);
    vis

  • [Tomcat bug?] Calling response.sendError(404) from JSP

    Calling "response.sendError(404);" from JSP context causes Tomcat to mangle all non-latin characters.
    Any ideas why?
    How to recreate bug:
    http://www.kitoy.ru/int/bug1.zip
    There are 3 files in bug1.zip.
    index..jsp:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@page pageEncoding="utf-8"%>
    <%@page contentType="text/html; charset=utf-8"%>
    <%
        response.sendError(404);
    %>
    <html>
    </html>404.jsp:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@page pageEncoding="utf-8"%>
    <%@page contentType="text/html; charset=utf-8"%>
    <html>
    <h1>Hello in Russian: &#1055;&#1088;&#1080;&#1074;&#1077;&#1090;!</h1>
    </html>and WEB-INF\web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
        <display-name>bug1</display-name>
        <description>bug1</description>
        <distributable/>
        <error-page>
            <error-code>404</error-code>
            <location>/404.jsp</location>
        </error-page>
    </web-app>Calling of index.jsp should cause 404 error with custom error page. The error page is utf-8 encoded and contains russian characters. That's by design.
    In fact, Tomcat shows ?????? instead Russian variant of "Hello".
    Tomcat/5.5.17 or Tomcat/5.0.28.- it does not matter.
    Is it Tomcat bug or I should not call response.sendError(404) from JSP?

    it's not a tomcat bug, it's rather a problem with
    your code.
    change index.jsp like the following then test
    it !
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@page pageEncoding="utf-8"%>
    <%@page contentType="text/html; charset=utf-8"%>
    <%
    esponse.sendRedirect("blablablablablabla.html");
    %>
    <html>
    </html>
    Thanks for the insight. But the issue here is with the response.sendError() method.

  • How to avoid Moved Temporarily page

    Hi,
    In my app, I use jsp with servelet, and the servelet acts as the "traffic cop", that is, the users fill up the form in jsp pages, and the jsp pages are submitted (post) to this servelet, this servlet do some work by calling other helper class and get the next jsp page to present, and use response.sendRedirect(page). The problem is the "sendRedirect" method, some user complain that they submit the form and got a page says "The document you reqested has moved temporarily" and there is a link, after the user clisk the link, it got the right page, and do another submit for next step, the same thing happed aggain.
    I checked the log file, the form post returns 302 code, and the next page (redirected by sendRedirect method) is invoked as GET and returns 200.
    what can I do to avoid the problem some user has by presenting the page directly?
    Thanks

    If you use "forward" instead of "redirect" that won't happen. It might even be a better design, since redirecting displays a URL in the browser's address bar that the client can use to go directly to the JSP instead of through your traffic cop.

  • How to avoid present 302 page

              Hi,
              In my app, I use jsp with servlet, and the servlet acts as the "traffic cop",
              that is, the users fill up the form in jsp pages, and the jsp pages are submitted
              (post) to this servlet, this servlet do some work and get the next jsp page to
              present, and use response.sendRedirect(page). The problem is the "sendRedirect"
              method, some user complain that they submit the form and got a page says "The
              document you reqested has moved temporarily" and there is a link, after the user
              clisk the link, it got the right page.
              I checked the log file, the form post returns 302 code, and the next page (redirected
              by sendRedirect method) is invoked as GET and returns 200.
              I thought about the forward, but the images in the jsp all has relative path,
              so the call will be /myservelt/images/...gif. That doesn't work.
              what can I do to avoid the problem and send the page directly?
              Thanks
              

              Thanks. I still can't have a good idea how to deal with. By reading it I may set
              the status code to 303 and get the post to be auto redirected, but this is the
              http1.1 new feature, I don't know what's the percentage of browsers support http1.1.
              I am assuming the older version browsers is for http1.0
              "Deepak Vohra" <[email protected]> wrote:
              >
              >For status codes refer to
              >http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Response-Status-Line.html
              >
              >
              >"John" <[email protected]> wrote:
              >>
              >>Hi,
              >>
              >>In my app, I use jsp with servlet, and the servlet acts as the "traffic
              >>cop",
              >>that is, the users fill up the form in jsp pages, and the jsp pages
              >are
              >>submitted
              >>(post) to this servlet, this servlet do some work and get the next jsp
              >>page to
              >>present, and use response.sendRedirect(page). The problem is the "sendRedirect"
              >>method, some user complain that they submit the form and got a page
              >says
              >>"The
              >>document you reqested has moved temporarily" and there is a link, after
              >>the user
              >>clisk the link, it got the right page.
              >>
              >>I checked the log file, the form post returns 302 code, and the next
              >>page (redirected
              >>by sendRedirect method) is invoked as GET and returns 200.
              >>
              >>I thought about the forward, but the images in the jsp all has relative
              >>path,
              >>so the call will be /myservelt/images/...gif. That doesn't work.
              >>
              >>what can I do to avoid the problem and send the page directly?
              >>
              >>Thanks
              >
              

  • Passing header to another servlet

    Hi guys,
    I'm trying to pass an 'Authorization' header from a servlet to another.
    I do something like this:
    String str = "root:12345678";
    String encodedStr = new String(Base64.encodeBase64(str.getBytes()));
    response.setContentType("text/html");
    response.setHeader("Authorization", "Basic " + encodedStr);
    response.sendRedirect("http://localhost:8080/Persister/servlet/DestinationServlet");
    In the doGet of the destination servlet i print the headers of the request but my 'Authorization' header is disappeared.
    Anyone can help me???
    Thanks,
    Massimo

    i think the answer lies in the question...
    Hi guys,
    I'm trying to pass an 'Authorization' header from a
    servlet to another.
    I do something like this:
    String str = "root:12345678";
    String encodedStr = new
    String(Base64.encodeBase64(str.getBytes()));
    response.setContentType("text/html");
    response.setHeader("Authorization", "Basic " +
    encodedStr);
    esponse.sendRedirect("http://localhost:8080/Persister/
    servlet/DestinationServlet");
    i think in destination servlet the header data is not submitted . i dont think you are able to get any data in the destination servlet as u are not sending anything to it. correct me if i am wrong
    In the doGet of the destination servlet i print the
    headers of the request but my 'Authorization' header
    is disappeared.
    Anyone can help me???
    Thanks,
    Massimo

  • Problem with sendRedirect using relative URL in WebLogic 5.1 with SP7 & 8

    I patched to SP 7 (and also 8), and the request.sendRedirect() with relative
              URL failed. The browser simply displayed "404 - Page not found".
              This problem only happens in a cluster environment attached to a web server.
              SP6 or earlier does not have such problem.
              I noticed that the latest SP always formats the URL and returns it as a full
              absolute URL to the browser. The problem is it uses the Weblogic Server host
              URL where the request is processed (not the Web Server host URL) which is
              not visible to the internet.
              Is it possibly a bug in SP?
              

    I patched to SP 7 (and also 8), and the request.sendRedirect() with relative
              URL failed. The browser simply displayed "404 - Page not found".
              This problem only happens in a cluster environment attached to a web server.
              SP6 or earlier does not have such problem.
              I noticed that the latest SP always formats the URL and returns it as a full
              absolute URL to the browser. The problem is it uses the Weblogic Server host
              URL where the request is processed (not the Web Server host URL) which is
              not visible to the internet.
              Is it possibly a bug in SP?
              

  • Problem with sendRedirect(..)

    Hi,
    here is my problem:
    I want to log in the user. I have login form, then I send request to the LoginServlet which verifies data and set session attribute (session.setAttribute("isLogin", "true")), then, if user and password is correct I use sendRedirect method to forward user to next page (somePage.jsp which contains an applet), and until now everything is ok.
    But when someone wants to use somePage.jsp without login it should check the session logIn attribute and if it is null it should forward to loginPage. Here is the servlet code which gets requests from somePage.jsp:
    public void doGet(HttpServletRequest request,HttpServletResponse response)
         throws ServletException, IOException{
              HttpSession session = request.getSession();
              Object done = session.getAttribute("logIn");
              if (done==null){//if user isn't logged
                   response.sendRedirect("/loginPage.html");
                   return;
    //user is logged
              if (session.getAttribute("someAttribute")==null)
              //... do something else
    And in this case sendRedirect method doesnt show loginPage. Maybe it's because an applet which is on somePage.jsp?
    I'm gratefull for any help.

    Hi,
    You look like you are losing you context root.
    When you send the redirect to "/loginPage.jsp", is means to send your page to something like "http://localhost:8080/loginPage.jsp", using the glassfish default hostname and port. I don't believe your page is located there.
    You want to try redirecting to "./loginPage.jsp" ( a period "." in front of the slash), this will use the same directory as the page that sent the request.
    You may also want to look at the RequestDispatcher that you get from the request to forward the page internally, so you don't have to send extra data over the net.
    There is an excellent JavaEE5 tutorial that may help you when researching these type of problems located at http://java.sun.com/javaee/5/docs/tutorial/doc/.
    Hope this helps...
    Thanks - Mark

  • Response.sendRedirect() problem

    Hi all,
    I in facing a problem during using response.sendRedirect() or there is some mistake, please help me...
    I have written two jsp files:
    i.e. first.jsp and second.jsp
    FIRST.JSP is as follwing:
    <%@ page import="java.io.*" %>
    <%
         response.sendRedirect("http://192.168.0.4:9999/mylogo/second.jsp");
    %>
    and SECOND.JSP is as follows:
    <%@ page import="java.io.*" %>
    <%
         String coding=request.getParameter("name").trim();
    %>
         My name is <h1><%= coding %></h1>
    but when i write the follwing in address bar:
    http://localhost:9999/mylogo/first.jsp?name=jake
    an error occurs:
    NullPointerException messae is received. I am using Apache Tomcat/4.1.29.
    Please help me, and tell if ther is any thing missing in this code....
    Thankx in advance...

    When you use redirection, you are sending a header back to the browser which tells it to go somewhere else. This results in an entirely new request. Because of this, any request info from the first page will not be in the second. The advantage of redirects is you can tell the browser to go to any other server.
    If you want to maintain the same request info, you can use forward. Forward only passes control in the server to another page. The browser will have no idea that this is happening, and it cannot go to another server.

  • Problems with sendredirect(url)

    Hi,
    I am using a sendredirect method in HttpServletResponse in order to redirect users from my site to other sites.
    I am using tomcat 5.x that is connected to IIS.
    The problem is that the statistics systems on the other sites do not see my users since there is no "Referer" field.
    What can I do? I tested it and saw no Referer field. How can I fix that?
    Thanks!

    You can always add the header manually before sending the redirect.

  • Response.sendRedirect(URL), problem if '&' is usd as part of paramete value

    i have to redirect to a page having following URL
    http://www.citease.com/afc/d&o_coverage.htm
    now & is part of value rather than a separater of parameters.
    whenever i redirect it as
    strURL = "http://localhost:8080/cms/redirector.jsp?ckUrl=http://www.citease.com/afc/d&o_coverage.htm";
    response.sendRedirect(strURL);
    it will not work properly, will try to access only
    http://www.citease.com/afc/d
    Please help.
    Best regards,
    Waseem Aslam

    Encode the URL, the & should be & amp;.
    You may find the URLEncoder useful.

Maybe you are looking for