Open a file in a servlet

Hi,
I am using Tomcat 4.0.4 as my servlet engine.
I have trouble in opening a file, when I want to open a file in current directory, I use
File counter = new File("counter.txt");
It points to the file c:\Tomcat\bin\counter.txt instead of the file in the directory d:\websites\servlets\WEB-INF\com\internal\servlet\counter.txt.
Is there any way I can open the file I want? Please help me and thank you in advance.

Thank you. I get it done.
One more question. will different servlet engine gives different result in getRealPath("/"). Just want to make sure this technique works across different servlet engine.

Similar Messages

  • PROBLEM while using URL in order to open a file from a servlet

    Hi,
    I am having a problem while trying to open a file from my servlet by using URL connection. Following is my code sample. what happens is when I first run my project it opens the file but after that when I rerun it again and again it sometimes opens it and sometimes not. if it can't open it it gives an error saying "the file is damaged and couldn't be repaired". I don't get any exceptions. if you guys can help me I will appreciate it so much... thanks.
    here is my code :
    URL url = new URL("http://demobcs.ibm.com:81/test.pdf");
    resp.setContentType(getContentType("http://demobcs.ibm.com:81/test.pdf"));
              ServletOutputStream sos = null;
              BufferedInputStream bis = null;
              try {
                   sos = resp.getOutputStream();
              } catch (Exception e) {
                   System.out.println("exception !!!!");
                   e.printStackTrace();
              System.out.println("burada2");
              try {
                   byte[] bytes = new byte[4096];
                   //bis = new BufferedInputStream(conn.getInputStream());
                   DataInputStream in = new DataInputStream(url.openStream());
                   //DataInputStream in = new DataInputStream(conn.getInputStream());
                   bis = new BufferedInputStream(in);
                   int j;
                   while ((j = bis.read(bytes, 0, 4096)) != -1) {
                        try {
                             sos.write(bytes, 0, 4096);
                             System.out.println("file is being read ...:");
                        } catch (Exception e) {
                             e.printStackTrace();
                   in.close();
                   bis.close();          
                   //sos.close();
              } catch (Exception e) {
                   System.out.println("exception :"+e.toString());
                   e.printStackTrace();
              }

    You are writing (<filesize> mod 4096) bytes of crap at the end of the file. Use your variable j instead for the number of bytes to write in your loop.

  • Opening a file from Servlet

    Hi,
    I`m trying to open a file from Tomcat Servlet init method but it fails with java.io.FileNotFoundException: test.properties (The system cannot find the file specified).
    The code is:
                                  File f = new File("test.properties");
                                  DataInputStream is = new DataInputStream((new FileInputStream(f)));
                                  System.out.println(is.readLine());
                                  is.close();
    test.properties is in /WEB-INF/classes directory.
    What is the classpath for a web app and is it possible to adjust it?
    Thanks,
    vs

    What is the error saying???
    Are you sure the file location is right?
    MeTitus

  • DeploymentException: error in opening zip file

    I get an deploymentexception during deploy to a clustered environment:
    If I during deploy from the Admin console select the option "I will make the deployment accessible from the following location", then no exception is encountered. But if I use default setting I get an error.
    The problem with using the above choice, is that managedServer running on a different server, does not see the jar file.
    Stack trace:
    <12.mar.2007 kl 19.47 CET> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
    weblogic.management.DeploymentException: error in opening zip file with : C:\bea\user_projects\domains\nb_domain\.\serve
    rs\ManagedServer_1\stage\siltool\siltool.ear
    at weblogic.application.internal.EarDeploymentFactory.findOrCreateComponentMBeans(EarDeploymentFactory.java:189)
    at weblogic.application.internal.MBeanFactoryImpl.findOrCreateComponentMBeans(MBeanFactoryImpl.java:48)
    at weblogic.application.internal.MBeanFactoryImpl.createComponentMBeans(MBeanFactoryImpl.java:110)
    at weblogic.application.internal.MBeanFactoryImpl.initializeMBeans(MBeanFactoryImpl.java:76)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationMBean(MBeanConverter.java:88)
    Truncated. see log file for complete stacktrace
    java.io.IOException: error in opening zip file with : C:\bea\user_projects\domains\nb_domain\.\servers\ManagedServer_1\s
    tage\siltool\siltool.ear
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:204)
    at java.util.jar.JarFile.<init>(JarFile.java:132)
    at java.util.jar.JarFile.<init>(JarFile.java:97)
    at weblogic.utils.jars.JarFileDelegate.<init>(JarFileDelegate.java:32)
    Truncated. see log file for complete stacktrace
    >
    <12.mar.2007 kl 19.47 CET> <Error> <Console> <BEA-240003> <Console encountered the following error weblogic.management.D
    eploymentException: error in opening zip file with : C:\bea\user_projects\domains\nb_domain\.\servers\ManagedServer_1\st
    age\siltool\siltool.ear
    at weblogic.application.internal.EarDeploymentFactory.findOrCreateComponentMBeans(EarDeploymentFactory.java:189)
    at weblogic.application.internal.MBeanFactoryImpl.findOrCreateComponentMBeans(MBeanFactoryImpl.java:48)
    at weblogic.application.internal.MBeanFactoryImpl.createComponentMBeans(MBeanFactoryImpl.java:110)
    at weblogic.application.internal.MBeanFactoryImpl.initializeMBeans(MBeanFactoryImpl.java:76)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationMBean(MBeanConverter.java:88)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationForAppDeployment(MBeanConverter.java:66)
    at weblogic.management.deploy.internal.MBeanConverter.setupNew81MBean(MBeanConverter.java:314)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.compatibilityProcessor(ActivateOperation.j
    ava:72)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.setupPrepare(AbstractOperation.java:295)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:86)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:718)
    at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1185)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:247)
    at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:15
    7)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(Deploymen
    tReceiverCallbackDeliverer.java:157)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiv
    erCallbackDeliverer.java:12)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCal
    lbackDeliverer.java:45)
    at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    Caused by: java.io.IOException: error in opening zip file with : C:\bea\user_projects\domains\nb_domain\.\servers\Manage
    dServer_1\stage\siltool\siltool.ear
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:204)
    at java.util.jar.JarFile.<init>(JarFile.java:132)
    at java.util.jar.JarFile.<init>(JarFile.java:97)
    at weblogic.utils.jars.JarFileDelegate.<init>(JarFileDelegate.java:32)
    at weblogic.utils.jars.VirtualJarFactory.createVirtualJar(VirtualJarFactory.java:24)
    at weblogic.application.ApplicationFileManagerImpl.getVirtualJarFile(ApplicationFileManagerImpl.java:194)
    at weblogic.application.internal.EarDeploymentFactory.findOrCreateComponentMBeans(EarDeploymentFactory.java:162)

    Even i am getting the same exception. The default staging option for my server is "No Stage". when i deploy the application i keep the default staging option but still it throws me the following exception
    weblogic.management.DeploymentException:
    at weblogic.servlet.internal.WarDeploymentFactory.findOrCreateComponentMBeans(WarDeploymentFactory.java:69)
    at weblogic.application.internal.MBeanFactoryImpl.findOrCreateComponentMBeans(MBeanFactoryImpl.java:48)
    at weblogic.application.internal.MBeanFactoryImpl.createComponentMBeans(MBeanFactoryImpl.java:110)
    at weblogic.application.internal.MBeanFactoryImpl.initializeMBeans(MBeanFactoryImpl.java:76)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationMBean(MBeanConverter.java:88)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationForAppDeployment(MBeanConverter.java:66)
    at weblogic.management.deploy.internal.MBeanConverter.setupNew81MBean(MBeanConverter.java:314)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.compatibilityProcessor(ActivateOperation.java:72)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.setupPrepare(AbstractOperation.java:295)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:86)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:718)
    at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1185)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:247)
    at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:157)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45)
    at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    java.util.zip.ZipException: Error opening file - /opt/app/user_projects/servers/m4/stage/app1/admin.war Message - error in opening zip file
    at weblogic.servlet.utils.WarUtils.existsInWar(WarUtils.java:65)
    at weblogic.servlet.utils.WarUtils.isWar(WarUtils.java:44)
    at weblogic.servlet.internal.WarDeploymentFactory.findOrCreateComponentMBeans(WarDeploymentFactory.java:54)
    at weblogic.application.internal.MBeanFactoryImpl.findOrCreateComponentMBeans(MBeanFactoryImpl.java:48)
    at weblogic.application.internal.MBeanFactoryImpl.createComponentMBeans(MBeanFactoryImpl.java:110)
    at weblogic.application.internal.MBeanFactoryImpl.initializeMBeans(MBeanFactoryImpl.java:76)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationMBean(MBeanConverter.java:88)
    at weblogic.management.deploy.internal.MBeanConverter.createApplicationForAppDeployment(MBeanConverter.java:66)
    at weblogic.management.deploy.internal.MBeanConverter.setupNew81MBean(MBeanConverter.java:314)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.compatibilityProcessor(ActivateOperation.java:72)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.setupPrepare(AbstractOperation.java:295)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:86)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:718)
    at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1185)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:247)
    at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:157)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45)
    at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    This happens on a cluster environment, on Solaris 10 with Weblogic 9.2, whereas it works well on Windows and Weblogic 9.1 and Solaris 9

  • Opening multiple excel files thorugh a servlet

    Hi
    In my system , i have excel reports in my server disk . And i am opening the excel files through an servlet class like /viewReport.do?id=23 .....and thus from the servlet will open my excel file .
    After opening one excel file , i try to open another excel by clicking that link , then my system often hangs else excel shows an error saying "a report with name viewReport.do is already open " even though both of these files are different on the server
    How can i avoid this ??
    The reason why i am opening the excel file through a servlet is , i need to perform some operations before opening that excel report
    Can any one let me know how to go abt this ??

    I had a similar porblem....
    I got some help from...http://www.javaworld.com/javaworld/jw-10-2006/jw-1019-xmlexcel.html?page=1...
    This is my code in servlet...
    HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet spreadSheet = wb.createSheet("Users");
         spreadSheet.setColumnWidth((short) 0, (short) (256 * 25));
         spreadSheet.setColumnWidth((short) 1, (short) (256 * 25));
    //     Creating Rows
         HSSFRow row = spreadSheet.createRow(0);
         HSSFCell cell = row.createCell((short) 1);
         cell.setCellValue("Year 2005");
         cell = row.createCell((short) 2);
         cell.setCellValue("Year 2004");
         HSSFRow row1 = spreadSheet.createRow(1);
         HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    cell = row1.createCell((short) 0);
    cell.setCellValue("Revenue ($)");
    cell = row1.createCell((short) 1);
    cell.setCellValue("25656");
    cell = row1.createCell((short) 2);
    cell.setCellValue("15457");
    FileOutputStream output = new FileOutputStream(new File("/tmp/Users.xls"));
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=Users.xls");
    ServletOutputStream out = response.getOutputStream();
    wb.write(output);
    output.flush();
    output.close();
    forward = null;
    In firefox i get the download dialog box but not able to open in from there,i need to save it and then open. In IE i dont get the dialog box instead the excell open inside the browser......Please help me to open a excel sheet onclick on a link "Export to excel" in jsp......
    Thanks in advance...
    Message was edited by:
    onlycoding

  • Opening a file with its filename from a servlet- avoid buffer to cach files

    Hi,
    I am building an URL with the following code and calling that particular file from this servlet using request dispatcher. When I am geting alcCode from getParameter method then it is not caching the pages
    but when I am geting the same through a session value it starts caching the page after cirtain number of requests and shows up the previously requested file.
    I guess it is because it always names the file with the package name.
    for example if my package is sree then the file opened is named as
    sree[1].pdf. Please help me solve this problem
    alcCode = req.getParameter("alcList");
    HttpSession userSession= req.getSession(false);//if request is from //submit action from a FORM
    String alcCode;
    alcCode = req.getParameter("alcList");
    System.out.println("request.getparameter alcCode "+alcCode);
    if (alcCode==null){
    alcCode= (String) userSession.getValue("alcCode");
    //else get the alc code from the session that has been stored
    Calendar todaysDate=Calendar.getInstance();
    int selectMonth=todaysDate.get(Calendar.MONTH);
    int selectYear=todaysDate.get(Calendar.YEAR);
    if(selectMonth <10)
    //selectMonth = InvoiceDate.substring(1,i-8);
    urlPdf="/reports/RPTS"+selectYear+"0"+selectMonth+"/PDF-FORMAT/E"+selectYear+"0"+selectMonth+"_"+alcCode+".PDF";
    }else{
    urlPdf="/reports/RPTS"+selectYear+selectMonth+"/PDF-FORMAT/E"+selectYear+selectMonth+"_"+alcCode+".PDF";
    res.setContentType("application/pdf");
    res.reset();
    res.resetBuffer();
    res.setHeader("Content-disposition","attachment; filename" +urlPdf );
    System.out.println(urlPdf);
    try{
    ServletContext sc = getServletContext();
    RequestDispatcher rd = sc.getRequestDispatcher(urlPdf);
    rd.forward(req, res);
    Thanks in advance.
    -Sreekanth Varidhireddy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I had a similar problem when I used the attachment argument to the Content-Disposition header.
    try replacing this:
    res.setHeader("Content-disposition","attachment; filename" +urlPdf );
    with this:
    res.setHeader("Content-Disposition","inline; filename=" +urlPdf );
    /Niklas

  • Open PDF file in a new browser window

    I have a PDF file on the harddrive and I call a function from BalusC :
    public static void downloadPDF(FacesContext facesContext, String path, String fileName)
    util.Logger.append("Path = " + path );
    util.Logger.append("file name = " + fileName);
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    File file = new File(path, fileName);
    BufferedInputStream input = null;
    BufferedOutputStream output = null;
    try
    //open file
    util.Logger.append("1");
    input = new BufferedInputStream(new FileInputStream(file), 10240);
    //Init servlet response
    util.Logger.append("2");
    response.reset();
    util.Logger.append("3");
    response.setContentType("application/pdf");
    util.Logger.append("4");
    response.setContentLength((int)file.length());
    util.Logger.append("5");
    response.setHeader("Content-disposition", "inline; filename=\"" + fileName + "\"");
    util.Logger.append("6");
    output = new BufferedOutputStream(response.getOutputStream(), 10240);
    util.Logger.append("7");
    //write file contents to response
    byte[] buffer = new byte[10240];
    int length;
    util.Logger.append("8");
    while ((length = input.read(buffer)) > 0)
    output.write(buffer, 0, length);
    util.Logger.append("9");
    //finalize task
    output.flush();
    util.Logger.append("10");
    catch (IOException e)
    util.Logger.append("reporting.Utilities :: downloadPDF :: " + e.getMessage());
    finally
    util.Logger.append("finally");
    close(output);
    close(input);
    //inform JSF that it doesn't need to handle response
    //this is very important, otherwise you will get the following exception in logs:
    //java.lang.IllegalStateException: cannot forward after response has been comitted
    facesContext.responseComplete();
    private static void close(Closeable resource)
    if (resource != null)
    try
    resource.close();
    catch (IOException e)
    e.printStackTrace();
    This works like a charm, but the problem is that the PDF is opened in current window instead of a new one. I checked posts on this problem on this forum but i haven't found any answer to my problem. As you can see i added some 'idiot' logs just to make sure i have no errors. I see them all in my log file and there is absolutely no error. I simply see the PDF in the same window.
    Can anyone help me, please?
    Thank you.
    (Pls tell me if you need any other information)

    My problem is that the parent form has 4 buttons and a grid.
    3 buttons are Add/Edit/Delete for records in the grid. Only the 4th button is the Print report and this is the only one i need to open in another page.
    Even if I create another page and I navigate to it, setting target of newly created page to open a new window will bring me the problem of having 2 windows to close once users wants to close the PDF which is kind of awkward.
    What is your advice?
    Thank you
    Marius

  • How to open KM file in the same window

    When we open KM file by /irj/go/km/docs/... link it is previewed in a new Internet Explorer window.
    We changed Targed property to Self for iView navigation in LayoutSet render but the image file is still opend in new Window.
    How to workaround this?

    We changed Target Window Type property value of ResourceRenderer of Navigation iView  to Self.
    When an authenticated user  tries to open KM file it is opened in the same window if file URL include /irj/servlet/prt/prtroot....
    If file URL contain /irj/go/km/docs/.. it is opened in new window.
    When an anonymous user  tries to open KM file it is opened in a new (popup) window.
    We need that anonymous user can open km files in the same window.
    How to work around this?
    We use light framework.

  • Problem opening excel file in new window

    Hi,
    I have a JSF application that sends an Excel file back to the user.
    My backing bean has a method that uses POI to generate the excel file and then write it to the servlet response.
    This works fine if I call the method from a command button, but this displays the file in the current browser window, whereas I want to open the file in a new window.
    I added an onclick javascript call to a command button which does a window.open() to open a jsp in a new window. The jsp contains an empty view, as I'm using an on-load phase listener to make the call to my backing bean method which should send the excel file when the file opens.
    However, when the window opens, I get an IE error message saying 'Could not open xxx.faces', and then an excel error message saying 'Could not open xxx.xls. This may be because the file does not exist, or the file is already open etc etc'
    However, I found that if the popup window goes through a servlet (which just forwards to the jsp page) instead of going to the jsp directly, it works like a charm.
    Any ideas or suggestions on how to fix this would be very much appreciated. If I can't fix it I'll just stick with the servlet approach, although it just seems a bit messy.
    (I'm using IE6 SP2, tomcat 5.5 btw)
    Cheers,
    Stuart

    I'm doing a similar thing, but I use commandLink to lauch the window. CommandLink has the "target" attribute that I set to _blank.  As you would expect, that opens up the page in the new window.                                                                                                                                                                                                                                                                                                                                                                                                       

  • Java.util.zip.ZipException error in opening zip file

    Hello all,
    We are using Sun Java System web server 6.1 SP2. When I tried to deploy an application, I received this message: "Posted content length of --- exceeds limit of --- " the -dashes are the size of the file actually.
    I then added an init-param to the web.xml specifying the maximum size.
    After doing that, I tried to deploy the war file using administration interface, but received a network tcp/ip error. I then deployed it using command line wdeploy command. It worked but the web server won't start up after the deployment. The following error messages are found in the log file. Any thoughts as to whats wrong here? Is there a bug in SP2?
    [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: URI='/search', ResourcePath='/WEB-INF/sun-web-search.tld' [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]:
    tldConfigJar(/WEB-INF/sun-web-search.tld): java.util.zip.ZipException: error in opening zip file
    [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: URI='/jstl-fmt', ResourcePath='/WEB-INF/fmt.tld' [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: tldConfigJar(/WEB-INF/fmt.tld): java.util.zip.ZipException: error in opening zip file
    [22/Sep/2006:17:30:48] failure ( 5668): CORE4007: Internal error: Unexpected Java exception thrown (java.lang.NoClassDefFoundError: org/xml/sax/ext/Attributes2, org/xml/sax/ext/Attributes2), stack: java.lang.NoClassDefFoundError: org/xml/sax/ext/Attributes2 at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1717) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:983) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1431) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1301) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at org.apache.xerces.parsers.AbstractSAXParser.<init>(Unknown Source) at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source) at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source) at org.apache.catalina.util.xml.XmlMapper.readXml(XmlMapper.java:274) at org.apache.catalina.startup.ContextConfig.defaultConfig(ContextConfig.java:882) at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1004) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:257) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:155) at org.apache.catalina.core.StandardContext.start(StandardContext.java:3752) at com.iplanet.ias.web.WebModule.start(WebModule.java:257) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133) at org.apache.catalina.core.StandardHost.start(StandardHost.java:652) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:355) at org.apache.catalina.startup.Embedded.start(Embedded.java:995) at com.iplanet.ias.web.WebContainer.start(WebContainer.java:431) at com.iplanet.ias.web.WebContainer.startInstance(WebContainer.java:500) at com.iplanet.ias.server.J2EERunner.confPostInit(J2EERunner.java:161) [22/Sep/2006:17:30:48] failure ( 5668): CORE3186: Failed to set configuration

    ooks like you are running into bug: 4719677
    When you deploy a web application using the Administration Server from a
    remote machine, the maximum upload size by default is 10 MB. This can be
    changed by editing the
    install-root/bin/https/webapps/instance-app/WEB-INF/web.xml file. In the
    servlet webappdeploy, insert an init param named maxUploadSize with a
    value in bytes specifying the maximum upload size. Example:
    <init-param>
    <param-name>maxUploadSize</param-name>
    <param-value>90000000</param-value>
    </init-param>

  • How to open a file with a link ?

    I am using servlets to design an application.
    The application supports uploading and downloading of .DOC and .RTF files.
    My problem is that I am opening an uploaded file via a link.
    OPen File
    The above is also working fine and opens the file in the IE browser.
    But my problem is that I want to open the file with MS-Word...as is done on many resume-building websites.
    1) How am I supposed to do that ?
    2) Can I specify ContentType="application/msword" in a link ?
    Please Help !!

    I did the foll. w.r.t a docbase.
    A docbase stores documents and assigns an unique id to each one. The foll. is a code snippet that opens a document's contents in a browser.
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    Connection conn = null;
    Statement stm;
    ServletOutputStream sos = null;
    ResultSet res;
    // .... get id of document u want to open
    query = "select id from .. where object_name = ' xx' .."
    res= stm.executeQuery(query);
    Blob blob = res.getBlob("_content"); // this will get content of document identified by id
    int blobLen = (int)blob.length();
    //the foll. is the part u need..
    if (blobLen > 0) {
    InputStream contents = blob.getBinaryStream();
    response.setContentType("application/msword"); // MS Word
    byte[] buf = new byte[blobLen];
    int length = -1;
           while ((length = contents.read(buf)) != -1){
              sos = response.getOutputStream();
              sos.write(buf,0,blobLen);
    sos.flush();
    System.out.println("Doc Received");
    contents.close();
      res.close();
      conn.close();
    }

  • File Download with Servlet

    In my application i have to download a file with the help of servlet.
    Everything works fine except the case where i want to open the dialog box or just let that file open in the browser.
    For e.g. when i am trying to download an excel file and i want to have a dialog box open for save, it doesnt does that but automatically open the file in browser.
    But for the above case if i dont set the "ContentType" as "application/vnd.ms-excel" then it works fine like it will open a dialog box if in the header the value of "Content-Disposition" has "attachment;" and will open it if it has "inline;"
    Could you guide me to some good study material on what can be issues or the fundamentals of setting the "fileName with extension", what if i dont set "ContentType" and what is the difference between "Attachment" and "Inline"
    Thanks

    actually youre using the trick most ppl use.. force the content type to be something else than the ms-excel..
    the content type is ment to be a guide to the browser on how to interprete the content..
    if it doesnt it will prompt you to download i.e. show the file save dialog..

  • How to open multiple files in Labview?

    I want to open multiple files in labview by selecting multiple files,then read them? Can I do this in Labview 7.0?

    You can use the vi example here to get multiple names:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=137&HOID=506500000005000000C7640100&HTHREAD=000091335&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
    Once you have the file names, you can use a for loop w/ a Read/Open file vi to open all the files.
    2006 Ultimate LabVIEW G-eek.

  • Problem on opening pdf file in IE inline (through streaming method)

    Hello
              I had a problem opening pdf file at IE through streaming. I create a page
              that have a hyperlink to open the new window and talk to a serlvet. When
              clicked, this serlvet will stream a pdf file from the file server to serlvet
              output stream. And the pdf file will be displayed within the browser.
              The problem comes that I can see the Acrobat Reader trailer screen display
              but the brower show nothing. I click refresh button to that serlvet to
              reload then it come up the content.
              Is anyone have the same trouble on this and any solution will be
              appreciated.
              Rondy Lee
              State Street Australia Ltd.
              

    Hello Rondy,
              You vae set mime type to application/pdf, which is good. But IE doesn't care
              of it !
              And I think your URL is too long because and I'm sure it leads to a buffer
              overflow (as they say at MS in their bug report).
              So as a workaround, you can rename your servlet mapping from Ecd/Download to
              Ecd/Download.pdf if you can, or make the URL length much more smaller.
              Try to go to MS site to find what is the precise bug#. I can't remember what
              it its number.
              I hope you'll find a solution.
              Dom
              "Rondy Lee" <[email protected]> a écrit dans le message news:
              [email protected]...
              > Thanks Dom, I will try to find it out
              >
              > This is the sample URL I used on local host:
              >
              http://ausyd1-wdev-01:7001/Datalightning/Ecd/Download?EcdId=20&Type=I&OpenMo
              > de=O&OutputType=PDF
              >
              > Also, I set content-deposition to "inline" to enforce IE to open the pdf
              > file. Content Type is application/pdf
              >
              > I hope this can tell more information.
              >
              > Rondy.
              >
              > State Street Australia Ltd.
              >
              > "Dominique Jean-Prost" <[email protected]> wrote in message
              > news:[email protected]...
              > > Hello Rondy.
              > >
              > > I already had problems using servlet streaming a pdf file to IE.
              > > What is the exact URL of your servlet ? IE has a bug : it does not care
              of
              > > the mime content you set up (I guess you made it). It only cares of the
              > > extension of the file it ties to read. In your case, I guess there is no
              > > extension because you're using a servlet. To look for the extension, it
              > > search the last dot in the URL, and it may have a problem it the URL is
              > too
              > > long (buffer overflow...).
              > > So you can map your servlet to an url which has a dot in its name, and
              > make
              > > the URL length smaller.
              > > I can't remember the IE bug #id but, it is official at MS.
              > > I hope this will help you.
              > >
              > > dom
              > >
              > > "Rondy Lee" <[email protected]> a écrit dans le message news:
              > > [email protected]...
              > > > Hello
              > > >
              > > > I had a problem opening pdf file at IE through streaming. I create a
              > page
              > > > that have a hyperlink to open the new window and talk to a serlvet.
              When
              > > > clicked, this serlvet will stream a pdf file from the file server to
              > > serlvet
              > > > output stream. And the pdf file will be displayed within the browser.
              > > >
              > > > The problem comes that I can see the Acrobat Reader trailer screen
              > display
              > > > but the brower show nothing. I click refresh button to that serlvet to
              > > > reload then it come up the content.
              > > >
              > > > Is anyone have the same trouble on this and any solution will be
              > > > appreciated.
              > > >
              > > > Rondy Lee
              > > >
              > > > State Street Australia Ltd.
              > > >
              > > >
              > > >
              > > >
              > > >
              > >
              > >
              >
              >
              

  • Downloading PDF file with a servlet

    I'm working on a web application that dynamicaly creates a PDF file and then writes each character to the ServletOutputStream. Ideally, the browser is supposed to recognize the "application/pdf" MIME type and force the file to be downloaded (or opened from current location if the user should choose). When I test it on my local system, the file downloads but it uses the servlet as the file name. On my webserver I get the following problems.
    1) On all the browsers I've tested (except Internet Explorer), the output is being printed in ASCII to the display which keeps the file from downloading. Internet Explorer is the only browser that will actually download the file.
    2) When it does attempt to download the file, it is creating a file with the servlet as the name as opposed to the filename that I am assigning during creation.
    I've been reading all the related posts that I could find in these Forums but haven't been able to find a solution. If anybody has any ideas, I would greatly appreciate your knowledge. Please note that I have set up MIME-mapping for the PDF extension in the WEB.XML file on my web server.
    Here is some servlet code that handles the PDF creation and download:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    InputStream in = null;
    ServletOutputStream out = null;
    String dir = "/www/mydirectory/";
    try {
    // Create the PDF file and retrieve the filename
    String filename = PDFCreator.main();
    //Flush the response stream and then reset it for writing a PDF to the display
    response.reset();
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename="+filename);
    out = response.getOutputStream();
    in = new BufferedInputStream( new FileInputStream(dir+filename));
    int ch;
    while ( (ch = in.read()) != -1 ) {
    out.print( (char)ch );
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if( in != null ) {
    in.close();
    if( out != null ) {
    out.flush();
    out.close();

    Your code looks correct.
    Apparently other people too have been having problems with pdf's. These links may help you solve the problem.
    http://forum.java.sun.com/thread.jsp?forum=54&thread=100793
    http://forum.java.sun.com/thread.jsp?forum=33&thread=250668
    http://forum.java.sun.com/thread.jsp?forum=33&thread=63282
    Redirecting may not be a good idea due to url hacking. Streaming the output would be the best way to go.

Maybe you are looking for

  • How to trigger a workflow using generic object services?

    Hi Experts, Let me know on how to trigger a workflow using generic object services. My requirement is to trigger the FI document reversal document using Object services. Any info or docs relevant to this, please share with me.. Thanks, Dinesh.

  • Problem with Casting

    Dear all, I have two classes PureABox and ABoxDL. ABoxDL is an extension of PureABox . When I tried to call the clone() of ABoxDL, I get the following error message: OntologyManager.PureABox cannot be cast to OntologyManager.ABoxDL What's the problem

  • List Export Spreadsheet

    Hi, I am trying to export my alv grid output into excel by List > Export > Spreadsheet and selecting table option. All the date is being exported to excel good till here, but columns are changing their positions. When I look little bit close I found

  • BAPI to delimit Infotype 0017.

    Hi All Is there any BAPI to delimit the Infotype 0017? Is yes, please provide me with a sample code of what all values to pass. I tried searching on the forums but couldn't get it. Thanks in advance. Harsh

  • Opening Aperture Library from my Drobo (Very Slow)

    I have a Firewire Drobo, which I love, and I use Aperture on my Mac. I currently have my primary Aperture Library (~125GB) on my Drobo. I have been experiencing an issue with slowness when opening my Aperture library from my Drobo. It takes several m