SetContentType and SJAS

Hi,
I'm trying to set the MIME type with response.setContentType().
However it turns out that the type is determined by SJAS's 'Forced Response Type' (Response type to be used if no available MIME mapping matches the extension) on the Configuration / HTTP Service / HTTP Protocol page.
How can I change this?
I'm using Sun Java System Application Server Platform Edition 9.0_01 (build b14)

The following servlet:
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
public class OTest extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        ServletOutputStream sos = response.getOutputStream();
        sos.print("Test-Header: testing\n\n");
        sos.print("Here is the first line of the HTTP response.\n");
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
}... produces the following server response:
HTTP/1.1 200 OK
Content-Length: 67
Date: Thu, 22 Jan 2004 12:54:16 GMT
Server: Apache-Coyote/1.1
Test-Header: testing
Here is the first line of the HTTP response.It appears that calling getOutputStream() flushes a default set of headers. Is there any way to intercept this output from the server and manually write header information? If not, is there a way, at least, to address the Content-Type problem I mentioned in my first post?
I am at a loss for direction on this problem. Any/all help is greatly appreciated.

Similar Messages

  • SetContentType and charset

    Is there any possible way to set the Content-Type header of a servlet response so that it does not append the "charset=ISO-8859-1" on the end of the header value?
    I would simply like to send a response that contains the header:
    Content-Type: application/pdf
    However, using setContentType("application/pdf"), creates a header that looks like this:
    Content-Type: application/pdf;charset=ISO-8859-1
    I NEED to chop off that charset value completely. Is there any way of doing this?
    All help will be greatly appreciated.

    The following servlet:
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class OTest extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            ServletOutputStream sos = response.getOutputStream();
            sos.print("Test-Header: testing\n\n");
            sos.print("Here is the first line of the HTTP response.\n");
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doGet(request, response);
    }... produces the following server response:
    HTTP/1.1 200 OK
    Content-Length: 67
    Date: Thu, 22 Jan 2004 12:54:16 GMT
    Server: Apache-Coyote/1.1
    Test-Header: testing
    Here is the first line of the HTTP response.It appears that calling getOutputStream() flushes a default set of headers. Is there any way to intercept this output from the server and manually write header information? If not, is there a way, at least, to address the Content-Type problem I mentioned in my first post?
    I am at a loss for direction on this problem. Any/all help is greatly appreciated.

  • Deployment error with JAX-WS using NB 5.5 and SJAS 9.0

    Hi,
    I'm trying to expose a session bean as a web service. My service parses MPP files. When a few specific classes are used, the service fails to deploy with a java.lang.NoClassDefFoundError (the class is very much in the classpath). All the other classes used in the bean are taken from the same jar! Removing the offending classes remove the problem. Pls help.
    Bean:
    for (ResourceAssignment a : allAssignments) {
                    net.sf.mpxj.Task task = a.getTask();
                    System.out.println("Task name: " + task.getName());
                    System.out.println("Outline number: " + task.getOutlineNumber());
                    System.out.println("Outline level: " + task.getOutlineLevel());
                    System.out.println("\nWBS: " + task.getWBS());
                    System.out.println("WSB level: " + task.getWBSLevel());
                    task = task.getParentTask();
                    if (!task.getNull()) {
                        System.out.println("Parent task name: " + task.getName());
                    System.out.println("\nAdding listener...");
                    task.addFieldListener(new FieldListener() {
                        public void fieldChange(FieldContainer container, FieldType type, Object oldValue, Object newValue) {
                            System.out.println("Inside listener...");
                            System.out.println("Data type: " + type.getDataType());
                            System.out.println("Name: " + type.getName());
    Stacktrace:
    Exception occured in J2EEC Phase
    java.lang.NoClassDefFoundError: net/sf/mpxj/listener/FieldListener
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2365)
    at java.lang.Class.getMethod0(Class.java:2611)
    at java.lang.Class.getMethod(Class.java:1579)
    at com.sun.xml.ws.modeler.RuntimeModeler.processMethod(RuntimeModeler.java:455)
    at com.sun.xml.ws.modeler.RuntimeModeler.processClass(RuntimeModeler.java:355)
    at com.sun.xml.ws.modeler.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:251)
    at com.sun.tools.ws.wscompile.CompileTool.buildModel(CompileTool.java:633)
    at com.sun.tools.ws.wscompile.CompileTool.run(CompileTool.java:538)
    at com.sun.tools.ws.util.ToolBase.run(ToolBase.java:56)
    at com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:44)
    at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1820)
    at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2089)
    at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:396)
    at com.sun.enterprise.deployment.backend.EjbModuleDeployer.deploy(EjbModuleDeployer.java:138)
    at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:160)
    at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
    at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
    at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
    at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)

    Update: It is working with SJAS 9.1 :). Now I'm sure it is a bug with SJAS 9.0. Still any clue will be appreciated.

  • Example using setcontenttype to write binary data?

    Hi there,
    I'm having trouble getting my jsp to read a binary file and send the response to an http client.
    I'm not sure what it could be between the getWriter, getOutputStream, setcontenttype, and other methods involved.
    Can anyone provide and/or point me to a simple example where a binary file is opened, read, and the contents sent back to a web-browser?
    Thanks!

    First, I would not recommend using JSP, but use servlets instead. If you have any newlines in the page like after <%@ page directives, you are can't write binary data. So you have to make all your page directives and everything have no newlines, making it ugly to read.
    Second, use getOutputStream() to write to...
    request.setContentType("application/octet-stream"); // or actual file mime type
    request.setHeader("Content-Length", theFileSizeInBytes);
    request.setHeader("Content-Disposition", "attachment; filename=" + theFileName); // if should do save as
    OutputStream os = response.getOutputStream();
    ...

  • How to  read from excel file and write it using implicit jsp out object

    our code is as below:Please give us proper solution.
    we are reading from Excel file and writing in dynamicaly generated Excel file.it is writing but not as original excel sheet.we are using response.setContentType and response.setHeader for generating pop up for saveing the original file in to dynamically generated Excel file.
    <%@ page contentType="application/vnd.ms-excel" %>
    <%     
         //String dLoadFile = (String)request.getParameter("jspname1");
         String dLoadFile = "c:/purge_trns_nav.xls" ;
         File f = new File(dLoadFile);
         //set the content type(can be excel/word/powerpoint etc..)
         response.setContentType ("application/msexcel");
         //get the file name
         String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
         //set the header and also the Name by which user will be prompted to save
         response.setHeader ("Content-Disposition", "attachment;     filename="+name);
         //OPen an input stream to the file and post the file contents thru the
         //servlet output stream to the client m/c
              FileInputStream in = new FileInputStream(f);
              //ServletOutputStream outs = response.getOutputStream();
              int bit = 10;
              int i = 0;
              try {
                        while (bit >= 0) {
                        bit = in.read();
                        out.write(bit) ;
    } catch (IOException ioe) { ioe.printStackTrace(System.out); }
              out.flush();
    out.close();
    in.close();     
    %>

    If you want to copy files as fast as possible, without processing them (as the DOS "copy" or the Unix "cp" command), you can try the java.nio.channels package.
    import java.nio.*;
    import java.nio.channels.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    class Kopy {
         * @param args [0] = source filename
         *        args [1] = destination filename
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                System.err.println ("Syntax: java -cp . Kopy source destination");
                System.exit(1);
            File in = new File(args[0]);
            long fileLength = in.length();
            long t = System.currentTimeMillis();
            FileInputStream fis = new FileInputStream (in);
            FileOutputStream fos = new FileOutputStream (args[1]);
            FileChannel fci = fis.getChannel();
            FileChannel fco = fos.getChannel();
            fco.transferFrom(fci, 0, fileLength);
            fis.close();
            fos.close();
            t = System.currentTimeMillis() - t;
            NumberFormat nf = new DecimalFormat("#,##0.00");
            System.out.print (nf.format(fileLength/1024.0) + "kB copied");
            if (t > 0) {
                System.out.println (" in " + t + "ms: " + nf.format(fileLength / 1.024 / t) + " kB/s");
    }

  • How to download data in xml format from a jsp in IE

    In my program, I am trying to download xml data from jsp. The problem I am facing is that the downloaded page opens in the browser itself. I want it to open in a new page. The same code works fine with csv and pdf format.

    Hello
    I am using a link that calls a javascript function. To show the file download box, I have used setContentType and setHeader functions in the jsp. Thanks.

  • A job I have seen was running since 11 hours but in history its duration is 48 minutes only

    SQL Server agent 2008 :
    A job I have seen was running since 11 hours but in history its duration is 48 minutes only.is It possible.
    Thanks

    Check all the steps and how much time each step took...
    SELECT sj.name
    , sja.*
    FROM msdb.dbo.sysjobactivity AS sja
    INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id
    WHERE sja.start_execution_date IS NOT NULL
    AND sja.stop_execution_date IS NULL
    http://thomaslarock.com/2012/10/how-to-find-currently-running-long-sql-agent-jobs/
    Raju Rasagounder Sr MSSQL DBA

  • Popup message 'Export In Progress' during export creation.

    Hello,
    Having problems closing a popup window which displays "Export in Progress" after my code creates the file and before I set response.setContentType and the Content-Disposition header (trying to close after is pointless). The problem is I can't close the popup. DId anyone find a solution to this problem?
    Sequence of events:
    Popup opens with Export options.
    User selects "Excel"
    The popup displays "Export in Progess"
    The "File Download" dialog opens and the user selects Open/Save/Cancel
    Problem --> The popup is still open.
    One idea is to redirect from ExcelCreator servlet to popup, close popup and then go back to ExcelCreator.
    If anyone has a link to an example or an idea the Please let me know.
    Thanks,
    Billy

    Check out this component from Coldtags suite:
    http://www.servletsuite.com/servlets/waittag.htm

  • Sun Application Server 8 response problem

    Hi forum. I�d installed moths ago SJAS 8 and it woks good. By any reason, I�d to uninstall it. But recently I reinstall te server, without any problem, and I can use teh "Start default server" on the Menu Start. But when I try to access the "localhost:8080", the browser stand hanged. And unusually, any browser in my system (netscape,iexplorer,opera,firefox) won�t work, even to load any site when the Server is working. The option "Stop default server" don�t working too. I�d try install SJAS 8.0, SJAS 8.1 and SJAS 8.1 multilanguaje, but with the same results. Even I�d try change the HTTP port from 8080 to 8282, but nothing happends. Any idea?

    Hi, again. Other details of my installation , The server is SUn Java System Application Server Plataform Edition 8.12005Q1, my machine is an AMD Athlon 1.25Mhz, with 256Mb RAM (Yes, slow for use the server, but it ran without troubles the first time I installed), The JDK is J2SE1.5.0_5 and JRE1.5.0_05. I had read the troubleshotting guide, and the server log register that the server successful finish the start up proccess, and the file domain.xml register correctly the "http-listener" on 8080 port. When I start to search the source of trouble, I remmember that I have the Tomcat 5.5 installed and using the 8080 port, then I uninstall the Tomcat, but the problem persist with the SJAS.

  • How to close browser window after flushing a file to the browser?

    I have this simple JSP, which flushes a String to the browser as a file (message.txt). The JSP gets opened in a new window when the user clicks a link.
    The problem is that after the JSP has run, the browser window won't close automatically. I've tried adding a small javascript to achieve this, but i doesn't seem to even get run.
    How can I close the browser window after the JSP has run?
    <%
         String someText = "bla bla bla";
         // Flush to browser
         response.setContentType("text/plain");
         response.setHeader("Content-Disposition", "attachment;filename=message.txt");
         try {
              ServletOutputStream os = response.getOutputStream();
              os.write(someText.getBytes());
              os.flush();
              os.close();
         } catch (IOException e) {
              return;
         } catch (Exception e) {
              return;
    %>
    <script type="text/javascript">
         window.close();
    </script>After the JSP has run, an empty html page with the following source can be seen:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
    <BODY></BODY></HTML>

    Try run this and you'll see that it runs fine with no exceptions:
    <%
         String someText = "bla bla bla";
         response.setContentType("text/plain");
         response.setHeader("Content-Disposition", "attachment;filename=message.txt");
         try {
              ServletOutputStream os = response.getOutputStream();
              os.write(someText.getBytes());
              os.flush();
              os.close();
         } catch (Exception e) {
              out.println("ERROR: " + e);
    %>It looks like that after I've closed the outputStream I can't do any more processing in the JSP. Even if I remove the setContentType and setHeader methods it still behaves this way.
    I'm starting to think that there's no way around this...??

  • Character Encoding Problem RequestDispatcher

    Hi Friends;
    I have a servlet and I use
    RequestDispatcher dispatcher = request.getRequestDispatcher(page);
                   response.setContentType("text/html;charset=UTF-8");
                   request.setCharacterEncoding("UTF-8");
                   PrintWriter out = response.getWriter();
                   //request.setCharacterEncoding("utf-8");
                   try {
                        dispatcher.forward(request, response);
                   } catch (ServletException e) {
                        e.printStackTrace();
                   } catch (IOException e) {
                        e.printStackTrace();
    for forward page. But if i forward a page, this pages' encoding isnot working. But if i refresh page it works.
    How can i handle this encoding.
    Thanks replies

    Hi Eray,
    It really doesn't make any sense (exept in very specific, well, exceptional cases) to call setContentType and/or getWriter on the response object before doing a forward (neither does calling setCharacterEncoding on the request object usually makes sense);
    request.getRequestDispatcher(page).forward(request, response);
    should be sufficient. I assume you forward to a jsp page? In case you want to enforce the response encoding of the content of the jsp page to be UTF-8, you can use this page directive at the top of your jsp page:
    <%@ page contentType="text/html; charset=UTF-8" %>
    I don't know why it does work when you refresh the page, maybe your browser configuration is not correct (in IE: Page/View > Encoding > Auto-Select)?
    Kind regards,
    Sigiswald

  • Downloading a file help needed - Urgent

    Can anyone let me know how do i download a file that resides in database(BLOB format) in different box(server) to the local client's machine without prompting for any of the download dialog box using java. Also after downloading the correct application should be launched to view the downloaded file.
    thanks in advance
    regds
    chandru.

    Hi kev,
    Even I have done the same thing using servlets. But, My question is,
    When i click the download button from my application. The file should be downloaded to a pre-defined directory in clients machine and then the approperiate application should be launched to view the file.All this operation should take place just at the click of download button. Is this possible?.
    thanks
    chandru
    I've done this using a servlet. Assuming that the
    user's browser has the correct plugin available then
    you can call res.setContentType() and set the
    mime-type of the file, then you can call
    res.getOutputStream and stream the value from the
    database (using the relevent getXxxStream method of
    the BLOB) directly to the output. If for example your
    content type is application/ms-word, then the word
    plugin will be loaded and the file will be displayed.
    If your problem is with Database access and not with
    the display of the file, you'll have to let us know.
    Hope this helps
    Kev ([email protected])

  • Can't redirect to a powerpoint mimetype...

    I want to monitor when a user is downloading a particular piece of content.
              When they click on the link for the content, it redirects them to a page
              which records the download and then I run a response.sendRedirect(urlString)
              to the URL of the content. The mime type of that of a powerpoint document
              ("application/vnd.ms-powerpoint"). This works great with IE, but when I try
              to do this in Netscape, it doesn't seem to recognize that it is a Powerpoint
              document and therefore does not use the Powerpoint plugin. Although
              Netscape does work if I use a direct HREF statement, but then I won't be
              able to run my code to record the download. I've tried tricking the browser
              by using response.setContentType and response.setHeader, but it still does
              not work. Any ideas on how I can control the reponse object following
              redirection to the .ppt document?
              Thanks in advance...
              

    I have seen your code and i don't think there is a problem with the concept of response.sendReditect(). only just check whether your initialization of status="I" or "E" within a try block is working or not. i.e. status is getting the required value or not.
    otherwise instead of sendRedirect you can simply post the message by forming a dummy HTML page. like
    StringBuffer strtemp=new StringBuffer("");
    strtemp.append("<HTML><HEAD><TITLE>dummy page</TITLE>");
    strtemp.append("<BODY><FORM METHOD='POST'>");
    strtemp.append("</FORM><SCRIPT>");
    strtemp.append(" window.document.forms[0].action='cmptr_menu.jsp';window.document.forms[0].submit();</SCRIPT>");
    strtemp.append("<input type='hidden' name=msg value='Competitor Record is added'>");
    strtemp.append("</BODY></HTML>");
    out.println(strtemp.toString());

  • How to close browser window after user log out

    Hi,
    Does anyone know how I can close browser window after user logs out. The scenario is when user clicks a log out button I will invalidate user session and close the browser right away in the backing bean.
    Your help would be appreciated.

    Try run this and you'll see that it runs fine with no exceptions:
    <%
         String someText = "bla bla bla";
         response.setContentType("text/plain");
         response.setHeader("Content-Disposition", "attachment;filename=message.txt");
         try {
              ServletOutputStream os = response.getOutputStream();
              os.write(someText.getBytes());
              os.flush();
              os.close();
         } catch (Exception e) {
              out.println("ERROR: " + e);
    %>It looks like that after I've closed the outputStream I can't do any more processing in the JSP. Even if I remove the setContentType and setHeader methods it still behaves this way.
    I'm starting to think that there's no way around this...??

  • JSF- How TO...?

    Hi all,
    I have created a JSF sample application using netbeans4.1 and sun java application server 7. and working fine..
    Then i tried the same code using JBuilder X and the same server. it giving "Cannot found facesContext" Error. Y?
    Can anybody help me?
    How to create a JSF application using JBuilderX (Not JBuilder2005) and SJAS 7.
    Thanks in advance.
    Ganesh

    it is a problem of configuration (check web.xml) and mainly, the mapping url

Maybe you are looking for

  • Open PDF in Adobe Reader

    Hi, I want to open local PDF file in Adobe Reader directly when i press button from flash. I wrote a code to open PDF like this: on(release){ getURL("sample.pdf"); But this will open pdf in browser not in Adobe reader. so any solution for this?

  • ITunes makes a copy of my music or just makes links?

    Hi everyone, I got a little question about iTunes that I don't know if true or not. I have a large amount of CD's all in MP3 and I always use iTunes to play, retouch and more with it and when I always add music to iTunes (just drag it into the window

  • Sharing photos with descriptions

    I'm trying to share my photos with captions.  How do you do this? (via flikr or mobile me websites?)

  • Lion and waking up iMac from sleep

    Since updating to Lion (iMac 24", 2.6 Ghz) when I awake the unit from sleep instead of the cursor on the screen  I get a dark spot  (tiny dark grey square) at the tip of it, that turns into a line when I move the cursor. Have to turn the unit off and

  • Experience with NIO client servers

    Dear Forum I am going to build a xml socket server and would like to use NIO rather than multi threadeding. What the server will do is accept client connections and run them on their own thread, these clients will then be able to send/recieve data in