Setting the response header through JavaScript

Hi guys
I have to show a file to the client using the browser, I have the file contents stored in my Blob Field in the Database. Now I want to display the file on clilck of a button called DOWNLOAD and then determine the type of file, correspondingly setting the contentType and setHeader of response object. How can i do that??? Please help me at ur earliest...
Thanx

Hi,
I have created a JSP Page that will send a picture to the browser based on an ID that it is passed. Hope this helps a bit.
Gr. Arjan
<%
     String strDiscId = request.getParameter("id");
     int discId = Integer.parseInt(strDiscId);
     Disc myDisc = new Disc();
     myDisc.retrieve(discId);
     response.setContentType("image/jpeg");
     response.getOutputStream().write( myDisc.getImage() );
     response.getOutputStream().flush();
%>

Similar Messages

  • Setting a response header in a CQ5 publishing instance

    I want to disable caching in a CQ component and I have the following line in my jsp (documentation):
    response.setHeader("Dispatcher", "no-cache");
    If I insert the component in a page and load the page in an authoring instance everything works as expected and I get an HTTP header named Dispatcher with the content no-cache.
    Now if I do the same on a publishing instance (same configuration with CQ_RUNMODE='publish' and same content) the component works but for setting the HTTP header.
    Any idea on why the two instances could behave differently?

    I checked that the code is published and I tried to generate a minimal example.
    While removing unnecessary stuff from the page I noticed that after a given threshhold the header is generated.
    This buy just removing HTML (no code). I reach a point where if I remove a simple
    <div></div>
    the page is correctly delivered with the header, if I insert it back the header is no more there.
    Could this be related to HTTP chunking? If yes how can I disable it to debug?

  • How do I set the response status code for a request in ADF?

    For example:
    I have a page accessible like page.jspx?id=$ID, in which $ID identifies an object stored in a database. The user navigates to page.jspx?id=abc. abc does not exist or has been deleted. I wish to set the response status code to 404 for the page request, like, for instance, https://docs.google.com/spreadsheet/ccc?key=abc does. How do I do this?
    PS: Changing the status code for subsequent partial submits on the page if the object is deleted while the user is on the page (e.g. if the user attempts to delete an already deleted object through a "Delete" button on the page) may also be desirable, but would probably not fit in as well with the ADF lifecycle or be as useful.

    Maybe I should be more specific about the current state of the code. It's something functionally similar in relevant portions to the following. For the purposes of this code, assume the ID maps only to a name, rather than a more complicated object:
    page.jspx looks like:
    <?xml version='1.0' encoding='utf-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
         xmlns:trh="http://myfaces.apache.org/trinidad/html" version="1.2">
         <jsp:directive.page contentType="text/html;charset=utf-8" />
         <f:view>
              <af:document binding="#{pageInitializer.dummyComponent}" title="#{pageData.name != null ? pageData.name : 'Object Not Found'}">
                   <af:outputText rendered="#{pageData.name != null}" value="#{pageData.name}" />
                   <af:outputText rendered="#{pageData.name == null}" value="No object was found at this URL." />
              </af:document>
         </f:view>
    </jsp:root>pageInitializer and pageData are pageFlow-scoped beans with the following code:
    class PageInitializer {
         @Inject private PageData pageData;
         @Inject private NameDao nameDao;
         @PostConstruct
         void initialize() {
              String name = nameDao.getNameById(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"));
              if (name != null)
                   pageData.setName(name);
              else
                   // TODO: Set status code 404
         public void setDummyComponent(UIComponent dummyComponent) {
         public UIComponent getDummyComponent() {
              return null;
    public class PageData {
         private String name;
         public String getName() {
              return name;
         public void setName(String name) {
              this.name = name;
    }The code initializes the data from the database through the initilaizer of a pageFlow-scoped bean with a dummy setter for the document because I read somewhere that that would work, and it seems to work, even though it seems hacky.
    Ideally, the code would render the 404 where it currently says (// TODO: Set status code 404). I realize this may not even be possible given the current architecture, because part of the response body has already been rendered, and I believe, but cannot find a source to cite, that the status code and headers cannot be set after the body has started being rendered. Is there any architecture that would get me this page's functionality (even if it's two JSPXs on the backend (which might be ideal)) and be able to render a 404 for an inexistent object?
    Edited by: 907794 on Feb 1, 2012 3:55 PM
    Edited by: 907794 on Feb 1, 2012 3:58 PM

  • How do I set the Track Header in such a way that both the solo and mute are turned off?

    How do I set the Track Header in such a way that both the solo and mute are turned off?

    Another possible solution is to use a battery grip on your 70D and see if the dial on the grip will change the shutter speed.
    There are some discussions about this problem on some earlier models Canon DSLR. Check it out.
    http://www.dpreview.com/forums/thread/2638326

  • Trying to set application item value through javascript

    Hi,
    I am not sure what I am doing wrong here can someone possibly shed some light? I have the following in my
    HTML Header of my login page
    <script language="JavaScript1.1" type="text/javascript">
    function setAppItem(val){
      var req = new htmldb_Get(null, &APP_ID., 'APPLICATION_PROCESS=dummy', 
      &APP_PAGE_ID.);
      req.add('F_LOGIN_MESSAGE', val);
      var gReturn = req.get();
      req = null;
    </script>
    <script language="JavaScript1.1" type="text/javascript">
    function doLogin()
      var err = false;
      alert(document.getElementById('P101_USERNAME').value);
      if((document.getElementById('P101_USERNAME').value == '') ||
        (document.getElementById('P101_PASSWORD').value == '')) {
        setAppItem('You must enter a username and password.');
        err = true;
      if(!err) {
        doSubmit('Login');
    </script>The setAppItem function does get called but it is not setting the application items text?
    Thanks in advance for any help!

    Thanks for all of your help Jari it is appreciated!
    For others the solution was to add the following to my HTML Source
    <div id="LOGIN_MESSAGE"></div>and then created the javascript routine
    <script language="JavaScript1.1" type="text/javascript">
    function setAppItem(val)
      $x('LOGIN_MESSAGE').innerHTML=val;
    function doLogin()
      var err = false;
      if($v('P101_USERNAME') == '' || $v('P101_PASSWORD') == '')
        setAppItem('You must enter a username and password.');
        err = true;
      if(!err)
        doSubmit('Login');
    </script>
    Thanks

  • Setting the JMS Header from Payload

    Hi Experts,
    My requirement is to send the payment data coming from ECC to non sap system.Sender adapter is proxy and receiver is JMS.ECC will be sending the filename in one field and payload content as a string in another field.PI has to set the filename coming from ECC in JMS header property.What configuration changes should i need to make in JMS adapter to achieve it?
    Converting the XML to string is possible in PI.But my question is converting the string XML data into XML fields is possible in SAP PI?If so how to do that?
    Please provide your suggestion.
    Regards,
    Karthiga

    Hi Karthiga,
    The UDF is there in blog
    DynamicConfiguration dynamicconfiguration = (DynamicConfiguration)param.get("DynamicConfiguration");
                DynamicConfigurationKey dynamicconfigurationkey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS", "DCJMSMessageProperty0");
                String s = dynamicconfiguration.get(dynamicconfigurationkey);
                CorrID.append(s);
    Please let me know if you have any issue.
    regards,
    Harish

  • How to set the SOAP Header while publishing to Queue in the mediator

    Hi,
    I am trying to publish the message to a JMS AQ, from the Mediator service in the 11g Soa Suite. I want to add some properties as SOAP Header to the message and send it to the JMS AQ. I have seen the mediator process calling BPEL process, passing the SOAP Header values. In the BPEL process, we have the section <soap:binding> inside that I can give the <soap:header>and set the values.
    Could any one tell me how to do this in Mediator service which is calling the JMS AQ using adapter?
    Thanks,

    The solution in this thread is for VS .NET as this is the forum for CR in .NET.
    With Foxpro, I suspect you want to create a new thread in the SAP Crystal Reports - Legacy SDKs forum.
    Make sure you specify the exact version of CR used.
    - Ludek

  • Setting the Color Settings (Illustrator - Javascript)

    I would like to set the right color settings file using a startupscript in Javascript.
    If the name of the color settings file to be set is "myColorsettings", I assumed this line should do the job:
    app.loadColorSettings ('myColorSettings')
    But it returns an error. What's wrong?
    The manuals tells me:
    app.loadColorSettings (filespec)
    Thanks,
    Peter

    Peter, I would expect that 'filespec' needs to be a 'file object' created with a string to the full location & name of file… Some thing like…
    var filespec = new File('/Library/Application Support/Adobe/Color/Settings/Recommended/Europe Prepress.csf');
    alert(filespec.exists);
    Sorry I don't have a version that supports this for me to test. Check for the existance of the target file then load… Oh my example was on my mac your OS may differ…?

  • How do I set the Http Header POST URL in SAAJ?

    Hi ,
    I am a newbie in the field of web services. I was trying to create a SOAP request with Http Header POST information having a POST url like
    the following:
    POST /OMASTI.xml HTTP/1.1
    Content-Type: multipart/related; boundary="eladeladeladeladeladeladeladeladelad"; type=text/xml; start=11814460
    Content-Length: 54596
    Host: unspecified
    SOAPAction: ""
    to that effect I did the following in the SAAJ client:
    MimeHeaders md = message.getMimeHeaders();
              md.setHeader("SOAPAction" ,"\"\"");
              md.setHeader("POST" ,"/OMASTI.xml");
    However what I got was :
    POST / HTTP/1.1
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    SOAPAction: ""
    POST: /OMASTI.xml
    Content-Type: multipart/related; type="text/xml"; boundary="----=_Part_2_32124414.1153146262750"
    Content-Length: 3352
    Cache-Control: no-cache
    Pragma: no-cache
    User-Agent: Java/1.5.0_07
    Host: www.google.com
    Connection: keep-alive
    I have two POSTs in the header. How do I fix it? Please Help ASAP.
    Regards,
    Zeus

    Hi,
    Please forgive my ignorance. I did the same as you said. and then checked the Http request being sent out using ethreal software... it was the same as I had told earlier. Is only POST supported by the connection object? And the does the URL that comes in the Mime header as POST refer to the URL to which the request was sent? what I mean is that if the mime header says
    POST /OMASTI.xml HTTP 1.1, does it mean that the URL that was passed to the connection object was "/OMASTI.xml" ? I had given the url as http://www.google.com to test the request being sent.. I only have a sample SOAP request which shows a HTTP header with the post url as I said before. I need to create a SOAP request with the same sort of Http header and the body needs to follow a certain OMA-STI protocol. My experience in the SOAP domain is almost nil. So please enlighten me.
    Thanks in advance,
    zeus

  • MODIFY THE RESPONSE HEADER VALUE IN IIS BASED ON THE QUERY STRING IN THE REQUESTED URL

    We Hosted a directory on IIS.
    The Files in the directory are saved with a Guid values.
    when there is a request from the client for a given resource ,we need to fetch the file name from the query string and modify the reponse header :" Content-Disposition",So that the User can Download with the requested name

    Sounds like a question for the ASP.NET forums:
    http://forums.asp.net
    Or the IIS forums in case you want to write some kind of module to do this without involving ASP.NET:
    http://forums.iis.net/

  • How to set the numeric format through the API

    Hi,
    I have an utility that imports limits from external resources and in that utility (C#) I would need to modify the numeric representation  so that what is defined as hexa in the external resource to be displayed as hexa after importing to TS as well.
    Can U help me out if this is possible with the API and if so, what is the right methods for it?
    Thanks in advance.

    Hi again,
    I didn't find straight solution yet, but I think it is good way around:
    http://digital.ni.com/public.nsf/allkb/1304B337E03E2E1A86257ACD004BAB06
    If you want hexadecimal representation you need to change "%b" to "%x". I'm still keep looking for a better solution...
    Best Regards

  • How to set response header in filter

    Hi,
    i want to set the response header in my security filter:
    private void setHeader() {
              FacesContext ctx = FacesContext.getCurrentInstance();
              if (ctx != null){
                   HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
                   response.setHeader("Pragma", "No-Cache");
                   response.setDateHeader("Expires",0);
                   response.setHeader("Cache-Control", "no-cache");
         }But ctx is always null? What am i doing wrong?
    Regards,
    barnti

    My understanding is you will not have Faces Context in a filter as you have not yet hit the faces lifecycle..
    Try the below to get the context.
         * (non-Javadoc)
         * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
        public void init(FilterConfig config) throws ServletException {
            setFilterCfg(config);
            setServletCtx(filterCfg.getServletContext());
         * Since your typical FacesContext.getCurrentInstance() will probably be
         * null due to the fact we have not hit the faces lifecycle yet, we must dup
         * some of the faces servlet code here to create a new current instance.
         * @param req
         * @param res
         * @return FacesContext which is fresh and virtually empty.
        protected FacesContext getFacesContext(ServletRequest req,
                ServletResponse res) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            if (facesContext != null) {
                return facesContext;
            //     Use the FactoryFinder to grab the Lifecycle object
            FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder
                    .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
            LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
                    .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
            Lifecycle lifecycle = lifecycleFactory
                    .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
            facesContext = contextFactory.getFacesContext(servletCtx, req, res,
                    lifecycle);
            ProtectedFacesContext.setFacesContextAsCurrentInstance(facesContext);
            return facesContext;
        }

  • Setting content-type response header in BlazeDS

    Per this JIRA ticket, http://bugs.adobe.com/jira/browse/BLZ-428 , there is a suggested fix that includes setting the response content-type header to text/xml.
    The JIRA ticket name is
    pinging endpoint Returns a HTTP: Status 200 in ie8
    and the suggested fix is:
    The problem appears to be completely worked around by setting the following headers in our HTTP responses to Flash:
    Content-Type: text/xml; charset=UTF-8
    Cache-Control: no-cache
    What is the best way to do this is if using BlazeDS?
    I have tried to set the content-type within my data service desitnation class, by accessing the HttpServletResponse from the FlexContext class, however this does not work.  The content-type is still "application/x-amf" in the response.    I am assuming that BlazeDS sets the content-type sometime after my data service desination code is invoked.
    I have also tried to create a servlet filter and set the content-type header both before and after (in a finally block) my data service code is invoked, however neither of these approaches successfully ended up with a content-type of "text/xml" in the response.  My sense is that setting the content-type prior to the data service destination code is too early in the chain and setting in the finally block is too late (per the servlet spec you cannot set the content-type after getWriter() has been called).
    Any ideas are appreciated.
    Also any other ideas on how to solve the general IE8 issue described in the bug above are appreciated.
    I am using...
    BlazeDS version: 3.2.0.3978
    Flex SDK version: 3.4
    App Server: JBoss 4.5
    Java: 1.5_16
    Thanks,
    Kevin

    Hi,
    in the meantime I found a "known issue" that seems to be related to my problem but it is said to be fixed with 10.0 MP1 (and we use 10.3):
    ChangeRequest number: CR316761, CR318708
    Description. The servlet container used to append charset=ISO-8859-1 to the HTTP Header contentType in the response for non-JSP pages with any charset contents. This would result in improper display of multibyte characters.
    This problem has been resolved.
    Maybe the information is wrong. I will examine the CR and may apply them on our 10.3 environment but I would be glad if some oracle/bea engineer would intervene here.
    Cheers
    Thorsten

  • Setting response header without scriptlet

    Can I set a response header from JSP without using a scriptlet?
    With scriptlets I can do <%response.addHeader("name", "header")%>
    but is there also a JSTL tag or similar to do it? (Except for writing a custom tag myself)

    As far as i know JSTL is not designed for this, as it is designed to work as a view language in the mvc model.
    And since you handle requests and responses in a controller, I don't think there will be something for JSTL.

  • Setting the header in http request object

    I am facing a problem while trying to test a particular flow of my application.The details are given below:
    The controller servlet of my main application reads the header "Referer" from the request object and then based on this it forwards the request to appropriate servlets.For testing my application I am writing a test servlet which receives a request object from a test jsp and sets all the necessary attributes in the request object and passes this request object to the doGet () method of the main application's controller servlet. But while trying with this I find that the main controller fails to forward to the correct servlet because it receives incorrect referer information. So my question is how can I set my customised "Referer" in the header of the http request so that the application's controller servlet forwards to the correct servlet?Is there any means to set the request header in servlet or jsp?

    As far as I know you can't change the request in a servlet or .jsp, but you can in a Filter. Wrap the original request object in a wrapper class before passing it to chain.doFilter().

Maybe you are looking for

  • JDEV 10G: how to display the value of the line chart using jChart in JSP

    I have draw the line chart in JSP using the JChart and now I wan to display the value label in the line there.. but the value wasn't show.. anyone can help me.. thx..

  • Help w/ exporting

    When i export a mpeg movie from quicktime to the ipod settings, and open it in itunes it has no sound. Does anyone know why and what I could do to fix this. Thanks

  • Some FAQ'S about timesten?

    Hi all, i m having some basic doubts pls let me know if anybody knows abt this since i m beginner i want to know these. 1.)what is timesten password? 2.)is it neccessary that oracle username and timesten account id both are same? 3.)what is the times

  • Auto Reversal or journal

    Hi All, I entered two JE and set it as auto reversal. However, the auto reversal did not occur. Can some one help me. Thanks in advance,

  • How to display an HTML or RTF or PDF in flash

    Hi all, Is there any way to display a simple html document inside an swf? Note that the html will contain text, bullets, tables and bookmarks, but no images or links. Thanks in advance