Gzip with servlet

Hi,
I am facing a problem with servlet which compresses the MS Excel files in gzip format,
when i try opening the Template.gz file using winzip or gzip.exe,it throws me an error as either " invalid zip file" or " archive directory not valid"
Can someone pls help in resolving this porblem,
Its very very urgent for me to solve this problem,
My servlet code snippest is as below,
I am using Microsoft Internet Explorer 6.0 to download template.gz file which supports gzip and deflate formats,
--------TemplateGenerator.java-----------------
public void doPost(HttpServletRequest req, HttpServletResponse res)
String encodings = req.getHeader("Accept-Encoding");
System.out.println(encodings);
res.setHeader("Content-Encoding", "gzip");
res.setHeader("Content-Disposition", "attachment;filename=Templates.gz");
try{
//First create User directory
String dir = "C:/";
String separator = System.getProperty("file.separator");
//Read the files in the current directory and write to zip file
GZIPOutputStream zip = new GZIPOutputStream(res.getOutputStream());
File dir1 = new File(dir);
File[] list = dir1.listFiles();
if(list == null)
System.out.println("No files");
else
for(int k=0;k < list.length; k++)
                                   int filelen = (int)list[k].length();
                                   System.out.println("File Length :"+filelen);
                                   FileInputStream fis = new FileInputStream (list[k]);
                                   byte[] tempfile = new byte[filelen];
                                   int bytesRead = fis.read( tempfile,0,filelen );
                                   // checking bytesRead not shown.
                                   fis.close();
                                   // write the contents into the zip element
                                   zip.write( tempfile , 0, filelen );
                                   zip.finish();
// close the entire zip
zip.flush();
zip.close();
-------------------------------------------------

Hi !
I am using following code to do that in my project, It might help you..
   String message = "your String" ;
            ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes());
            InputStreamReader isr = new InputStreamReader(bais);
            XmlPullParser pp = new KXmlParser();
            pp.setInput(isr);-Jestan

Similar Messages

  • Communicate with servlet after using Java Web Start?

    Is it possible to communicate with servlet to get data back and forth
    after using Web Start to download the client application?
    The demos come with Java Web Start are applications which are
    standalone, don't need communicate with the servlet on Web server
    after being launched. I am wondering if it is possible, and how (HTTP
    & JAX-RPC)?
    Thanx in advance.

    I've done this using HTTP. I get the server and port from the codebase:
    BasicService bs = null;
    try {
    bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
    String codeBase = bs.getCodeBase().toString();
    and use the java.net.HttpURLConnection and java.net.URL classes to send HTTP parameter values to the servlet and to receive results from the HttpURLConnection's input stream.

  • Displaying *.pdf file on browser with servlet

    hi all
    this RAMESH,struggling to display a pdf file on browser from a remote mechine
    earlier i tried with servlet
    response.setContentenType("application/pdf")
    out.println();
    by this i am getting only some data as below
    endobj
    4 0 obj
    <<
    /ProcSet [ /PDF /Text /ImageB ]
    /Font << /Fo0 21 0 R /Fo12 24 0 R /Fo13 27 0 R /Fo16 30 0 R /Fo18 33 0 R /Fo19 36 0 R >>
    >>
    endobj
    For this purpose i have gone thru www.lowagie.com
    and gone thru all examples but i am not getting how to display on browser or at least awt frame
    please requesting all for suggest me some way
    tanks all
    -Ramesh

    are you trying to
    a) create a PDF dynamically
    b) send an existing PDF

  • How to use JNI with Servlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    hi,
    I am also facing the same problem,
    when I am using JNI with stand alone application it works fine but when i tried to use it with a servlet It gives unsatisfied linker error
    stack: java.lang.UnsatisfiedLinkError: createSocket
         at RelayConnector.createSocket(Native Method)
         at RelayServlet.doGet(RelayServlet.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:891)
         at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:458)
    It seems i have to do some path settings in my iplenet web server.
    If some one have faced the problem i would be glad to know the solution for this, i am literally bugged up,....

  • Problem with Servlets

    Hi,
    I am Tejas , a newbie with servlets. Now, I have a servlet which contains a Javascript method. On clicking a link , the Javascript method is called.
    But however, I find that there is some trouble. I created a class called MainFrames.java, the object of which I am instantiating in the Javascript method.
    But this code doesnt work properly. I have given the snippet below
    out.println("<script type='text/javascript'>");
    out.println("function threader()");
    out.println("{");
    out.println("alert('Inside Threader');");
    out.println("<%@ page import=\"XcForm.MainFrames\"%>"); //I have a hunch that this statement is the problem
    out.println("<%");
    out.println("MainFrames mainframes = new MainFrames();"); //without the import statement above, the MainFrames.java class is not being recognised
    out.println("%>");
    out.println("}");
    out.println("</script>");
    Thanks in advance,
    Tejas

    Do not put presentation code in servlets. Put them in JSPs. And mixing serverside code (scriptlets) and clientside code (javascript) this way is indeed not going to work. That code will certainly not be executed in the order as you write. Serverside code is executed at the server and is finished when the response is completed. So any serverside code inside clientside code is alreay executed. Clientside code is executed at the client and will only execute when the response is completed (onload, etc) or when the client invokes it (onclick, onsubmit, etc). Further on, do not put business code in presentation code. Put them in servlets.

  • JSF 1.2 with SERVLET 2.3

    Hi, i've download the latest JSF 1.2 RI but i can't see any page as i get the following error:
    ava.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getContentType()Ljava/lang/String;
    at com.sun.faces.context.ExternalContextImpl.getResponseContentType(ExternalContextImpl.java:277)
    at com.sun.faces.renderkit.RenderKitImpl.createResponseWriter(RenderKitImpl.java:167)
    at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
    The getContentType method that the exception describes is only available in servlet 2.4 but i'm using a servlet 2.3 only container. Can i use JSF 1.2 with servlet 2.3 ?
    Thanks

    I'm 90% sure that you cannot. JSF 1.2 is intended to be part of Java EE 5.0. Since Servlets 2.3 are part of J2EE 1.3, I don't think that it will work.
    Adam

  • Some problems with servlet.jar and tomcat 4.1.27

    Hello everybody,
    I used to work with tomcat 3.3.1 and i've decided to use tomcat 4.1.27 now. The manual explains that we have to change de version of servlet.jar, it's done with servlet-2.3.jar but on tomcat starting i have this message:
    jar not loaded. See servlet spec [...]. Offending class: javax/servlet/Servlet.class
    what can i do, i've red all de documentation and i think all versions a OK??
    thanks per advance
    antoine

    I am running Tomcat 4.1.18, so your configuration may be slightly different. I found the Servlet.class file you are missing residing in the Tomcat/common/lib directory in the Servlet.jar file. Check your path and also make sure your Servlet.jar file contains the missing class.

  • Communicating with Servlets....

    hi!
    Wat are all the different ways in which the JSP used to communicate with Servlet?
    Thanx,
    Rgds,
    Sasi

    Jsp page communication with Servlets....
    web.xml -- Servlets loaded during application startup
    struts config -- Servlet mapping (w.r.t struts).
    and u can import servlets in jsp and can use it... there are so many possible ways of using servlets coz jsp pages inturn convert into servlets and got executed.....

  • Forward with servlets

    Im using tomcat 4.06 and i have some problems with servlets and forwarding:
    This is my servlet:
    import java.io.PrintWriter;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletContext;
    public class NTenant extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    String email = request.getParameter("tenant");
    //insert new tenant into database.
    System.out.println("Redirigiendo");
    ServletContext sc = getServletConfig().getServletContext();
    RequestDispatcher rdNext = sc.getRequestDispatcher("/tenantForm.html");
    rdNext.forward(request, response);
    System.out.println("Redirigido");
    I get this error:
    type Status report
    message Servlet invoker is currently unavailable
    description The requested service (Servlet invoker is currently unavailable) is not currently available.
    This is my dir structure:
    webapps\form\NewTenant.html
    webapps\form\tenantForm.html
    webapps\form\WEB-INF\web.xml
    webapps\form\WEB-INF\classes\NTenant.class
    webapps\form\WEB-INF\classes\TenantServlet.class
    The problem is that i cannot find my html, what must i write here? sc.getRequestDispatcher("/tenantForm.html"); <-----
    Thank you very much

    I heve tried with "../tenantForm.html"
    java.lang.IllegalArgumentException: Path ../tenantForm.html does not start with a "/" character
         at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:572)
         at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:174)
         at NTenant.doPost(NTenant.java:19)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    Now Im trying with:
    RequestDispatcher rdNext = sc.getRequestDispatcher "/../tenantForm.html");
    And I got:
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
         at NTenant.doPost(NTenant.java:20)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:465)
         at org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:216)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:536)
    Any other idea?

  • Dialogs with servlets

    Hi
    Does anyone know how to use dialogs with servlets? I'd like to show a confirm dialog on the client machine. My first idea was to use JOptionPane.showConfirmDialog as such in the servlet, but then of course de dialog pops-up on the server side, and not on client side.
    Many thanks for the help,
    Nic

    You need to use javascript to confirm, ask questions, etc...
    You can see :
    http://www.webreference.com/programming/javascript/confirm/
    Or
    http://www.bodo.com/javacool.htm
    Fred

  • Swings with servlets

    Hi,
    how we can use swings with servlets or jsps.
    or
    how we can display the browser in the swings.
    please give me a valid answer with examples.

    Hi,
    Your question is not clear... are you trying to display HTML using swing components or are you trying to use swing in a server-side application?
    Some Swing components (e.g. JLabel) natively support simple html, so:
    JLabel lbl = new JLabel("<html>hello <b>world</b></html>");would result in a JLabel that looks with the word "world" in bold. If you need also frames, css and javascript support - you'll need to reach for a 3^rd^ party library, I'm afraid.
    As for using swing in servers, look at this article:
    http://today.java.net/pub/a/today/2006/04/20/bringing-swing-to-the-web.html
    If you meant neither, please explain more.
    Hope this helps, though.
    Michael Bar-Sinai

  • [Help] To prevent timeout error of browser in clinet with servlet in server

    Hi all,
    If a browser (for example, Internet Explorer) do not get any response from a server for more than sometime (in case of IE, default is 5 min), it will stop waiting and return some timeout error message.
    But I have a servlet, which has a really long-time(at least 10 min) job to do before it could send a response to the browser. So, before the browser in client can get the result, it stops waiting.
    I know I can change the time-out setting of browser in client machines, but there are hundred of thousands.
    So, what I am asking is if it is possible to do it with servlet in server, and how?
    (for example, send something to the client every few minutes, but I do not know how to do it .)
    thanks a lot!

    What you would have to do is set up some sort of 'Buffer' servlet.
    It starts the job in the background, and then returns a page saying job started - client does not time out.
    You would have to start it in a seperate process - probably a new Thread.
    The client would then have to send back requests asking - is it finished yet?
    While the job is not finished the buffer servlet returns a "not yet" message.
    On completion, the job can be sent back to the client.
    Couple of pointers:
    It may be easier to have the background process generate the result to file - then your buffer servlet can just pick up the file when it is completed.
    To get your page to refresh multiple times, you can use javascript: window.setTimeout("[reload page]");
    Good luck,
    evnafets

  • Help with servlet

    I have a project with servlets in the 2 following folders
    myprojects and myclasses
    In my projects I have the helloProject and inside it I have the helloHtml folder and the helloPackage.
    So in the helloHtml folder I have the hello.html file and in the helloPackage I have the Hello.java (which is the servlet)
    when I compile this .java file the class file is inserted in the file myclasses\helloProject\helloPackage
    First in the file hello.html I have the code
    action="http://localhost:8080/servlet/helloPackage.Hello
    and so the servlet is executed fine.
    The problem is that I need to put a button in the code of Hello.java
    so that I can have reloaded the first page which is the hello.html
    But I am confused if I write onclick=history.go(-1) I have what I want but this page is not reloaded so I have some parameters there that I do not want
    Can I write sth like onclick=location.href=http://locahost:8080/.....??
    Could you please give me an advice considering the above description of my files??
    Thank tou very much....

    use sendRedircet(String AbsoluteURL) to send the Browser a redirect header so the browser send a new (fresh) request to the serlvet (with any parameter you specified).

  • Help needed. Problem with servlet.

    Hello ppl. Ok. I've never really needed to implement servlets in my projects before but I experimented by writing a simple helloworld servlet. It compiled successfully and I tested it in the examples servlet dir and it worked. To test it in the ROOT dir, I placed the servlet in the ROOT/WEB-INF/classes folder and edited the web.xml file with:
    <servlet>
              <servlet-name>HelloWorldExample</servlet-name>
              <servlet-class>HelloWorldExample</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>HelloWorldExample</servlet-name>
              <url-pattern>servlet/*</url-pattern>
         </servlet-mapping>
    When I try and execute the servlet by using this URL: localhost:8080/servlet/helloworld I get an internal server error and the server crashes. I removed the entry from the web.xml file and Tomcat started up again. What went wrong? Can someone enlighten me in how to get my test servlet working becuase i may use them in the future. Thanks.

    Nope, Still didnt work. As soon as I put in:
    <servlet>
         <servlet-name>HelloWorldExample</servlet-name>
         <servlet-class>HelloWorldExample</servlet-class>
         </servlet>
         <servlet-mapping>
         <servlet-name>HelloWorldExample</servlet-name>
         <url-pattern>servlet/HelloWorldExample</url-pattern>
         </servlet-mapping>
    Tomcat went offline!
    I have another entry which is:
    <servlet>
              <servlet-name>org.apache.jsp.index_jsp</servlet-name>
              <servlet-class>org.apache.jsp.index_jsp</servlet-clas
    >
         </servlet>
         <servlet-mapping>
              <servlet-name>org.apache.jsp.index_jsp</servlet-name>
              <url-pattern>/index.jsp</url-pattern>
         </servlet-mapping>
    Do you think they may be conflicting? Thanks.Tomcat going offline is quite weird. However,
    <url-pattern>/index.jsp</url-pattern>
    this is perfectly valid. Lemme ask you this: did u come up with this stuff on your own or was it generated for you by the container? It looks like it was generated upon compilation of the jsp. If that is the case it should cause any conflicts. However now if you want to invoke the servlet/jsp you must use a URL like:
    http://localhost:<PORT_NO>/index.jsp
    Cheers

  • Jsf with servlet 2.2

    help deployment java server faces with servlet 2.2
    best regars

    I'm 90% sure that you cannot. JSF 1.2 is intended to be part of Java EE 5.0. Since Servlets 2.3 are part of J2EE 1.3, I don't think that it will work.
    Adam

Maybe you are looking for

  • Creating Links in DW with PS3 web Photo Album

    How do you create code links in DW on a PS3 web Photo Album I created an imported into DW to includ in my web page? You can veiw the photo album in my web site surfingpictureseast.com in the football section titled "Test of Photoshop Web Photo Album.

  • How to Insert WMV or MOV in DreamWeaver?

    Hello All, I'm new to DW CS3, and I haven't worked with web pages in some time now. I thought that in earlier versions of DW it had a function to place/insert MOV and WMV files? How can I do that in DW CS3? Thanks in advance

  • Keyboard Lights won't turn ON

    My keyboard lights suddenly won't turn on. I don't know what the problem is. I tried clicking on the F6 button which will turn the lights on, but this time it appears a NO sign when I clicked on it. Please advice.

  • [URGENT]Error in OWSM gateway.

    Hi Mathias , Oracle SOA suite version: 10.1.3.1.0 I started the OWSM with the quick start tutorial. Instead of using the time service I used another service deployed. When I started I had created a gateway which I then deleted. Then I created a new g

  • SD: Need to cancel Goods Issue for Outbound delivery cancellation via VL09

    Hello. User have have canceled the GI for OBD via VL09. But the date of cancelation is 09.11.2010 though it should be 29.10.2010 (as it was in the initial document). Is there any possibility to cancel this cancellation? Best regards.