Setting response.setStatus

Dear Sirs,
How can I set the HTTP 1.1 Status Code, for example, for 413 ( Request Entity Too Large ) and then use it on the site.
Thank you

Sharif wrote:
Dear nclow,
Thanks a lot for your reply.
I understand how to set it but how will I use it after I have set. For example something like
if
response.setStatus(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE ) (may be if it is larger than say 100 character)
then redirect to, say for example, tooLargeError.jsp.
How will I do that please
Thank youYour question makes no sense. The status code is a string sent in the headers of the response back to the client who made the request. Your code is generating the response. setStatus returns null. You cannot test the result of this because all you are doing is setting something.
If you want to send a 413 code and a response that contains a pretty error message along with it, then YOU have to decide when a 413 is appropriate. Once you have determined in the code that you want to do this, you can set the header to 413, generate that error message however you want (e.g. hard-coded html, calling a method that returns an appropriate html response, calling another servlet, forwarding the processing jsp:forward, etc.) and return the response as normal.
A better description of why you're sending a 413, when you would want to send it, and what you want to happen would elicit a better answer.

Similar Messages

  • Can i user response.setStatus(301) and sendRedirect( url ) together ?

    in my redirect page , according to a condition i am setting the status as MOVED_PERMANENTLY on a condition in the same time i am directing this to a different URL
    res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    ((HttpServletResponse)res).sendRedirect(rvo.getToURL());
                                       req.getSession().getServletContext().getRequestDispatcher(rvo.getToURL()).forward(req,res);but every time after redirect it is still throwing 302 ( moved temporarily ) ( i checked this through live HTTP headers )
    can any one please help me

    Sorry Dr Clap,
    I was asking the code if anyone have
    I tried the code below
    response.setStatus(301);
    response.setHeader( "Location", "http://www.new-url.com/" );
    response.setHeader( "Connection", "close" );It is working only for those URLs which has specific file name on it
    for eg :
    http://softwarewip3.corp.emc.com:1001/about_us -- Fails
    http://softwarewip3.corp.emc.com:1001/about_us/index.htm  -- Works Can any one please help me it is URGENT !!

  • Set 'Responsive Design View' as a default view

    Is there a way to set 'Responsive Design View' as a default view every time I open a page?
    Thanks in advance.

    Hi lanapetkovic,
    Thank you for your question. Currently there is a keyboard shortcut to open up Response Design View.
    [https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly Keyboard Shortcuts in Firefox]
    However this is the second question about this, I created a bug to request this: [https://bugzilla.mozilla.org/show_bug.cgi?id=1045785]

  • 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;
        }

  • NullPointerException while setting response object encoding.

    I am getting Null Pointer Exception at line "esponse.setCharacterEncoding(encoding);", here the encoding value i am getting is "UTF-8". The same code works fine in other webservers like websphere/tomcat. Please let me know is there any specific setting or i need to set the encoding in different way in weblogic. Weblogic 10.3.1.0 - 64 bit.
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;
    * Take this filter out of service.
    public void destroy() {
    this.encoding = null;
    this.filterConfig = null;
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Conditionally select and set the character encoding to be used
    if (ignore || (request.getCharacterEncoding() == null)) {
    String encoding = selectEncoding(request);
    if (encoding != null){
    request.setCharacterEncoding(encoding);
    response.setContentType("text/html");
         if( encoding != null)
              response.setCharacterEncoding(encoding); //Error at this line
         else
              response.setCharacterEncoding("UTF-8");
         System.out.println("response content after :"+response.getContentType());
    // Pass control on to the next filter
    chain.doFilter(request, response);
    * Place this filter into service.
    * @throws ServletException
    public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
    String value = filterConfig.getInitParameter("ignore");
    if (value == null)
    this.ignore = true;
    else if (value.equalsIgnoreCase("true"))
    this.ignore = true;
    else if (value.equalsIgnoreCase("yes"))
    this.ignore = true;
    else
    this.ignore = false;
    * Select an appropriate character encoding to be used, based on the characteristics of the current request and/or filter initialization
    * parameters. If no character encoding should be set, return null.
    protected String selectEncoding(ServletRequest request) {
    return (this.encoding);
    }

    I am getting Null Pointer Exception at line "esponse.setCharacterEncoding(encoding);", here the encoding value i am getting is "UTF-8". The same code works fine in other webservers like websphere/tomcat. Please let me know is there any specific setting or i need to set the encoding in different way in weblogic. Weblogic 10.3.1.0 - 64 bit.
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;
    * Take this filter out of service.
    public void destroy() {
    this.encoding = null;
    this.filterConfig = null;
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Conditionally select and set the character encoding to be used
    if (ignore || (request.getCharacterEncoding() == null)) {
    String encoding = selectEncoding(request);
    if (encoding != null){
    request.setCharacterEncoding(encoding);
    response.setContentType("text/html");
         if( encoding != null)
              response.setCharacterEncoding(encoding); //Error at this line
         else
              response.setCharacterEncoding("UTF-8");
         System.out.println("response content after :"+response.getContentType());
    // Pass control on to the next filter
    chain.doFilter(request, response);
    * Place this filter into service.
    * @throws ServletException
    public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
    String value = filterConfig.getInitParameter("ignore");
    if (value == null)
    this.ignore = true;
    else if (value.equalsIgnoreCase("true"))
    this.ignore = true;
    else if (value.equalsIgnoreCase("yes"))
    this.ignore = true;
    else
    this.ignore = false;
    * Select an appropriate character encoding to be used, based on the characteristics of the current request and/or filter initialization
    * parameters. If no character encoding should be set, return null.
    protected String selectEncoding(ServletRequest request) {
    return (this.encoding);
    }

  • Setting response HTTP status code

    Hi all,
    it's possible to set a response HTTP 202 status code for Axis?
    Thanks Pasquy.

    Not sure if you're aware of this, but the status codes that must/should be used are specified in the SOAP HTTP binding spec and the Basic Profile.
    See http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html (see, e.g., s4.3.6), and the SOAP spec.
    That said, apparently 202 is acceptable in some circumstances, and I'm not sure on how to set the response code with Axis.
    -Tim

  • 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 response header fron JSP

    Hi
    I would like to know how I can set "If-Modified-Since" header, so that when client refreshes the page again the server should send 304 (Not Modified) status to the client.
    I was able to do this in servlets as follows,
    {code}
    class Servlt extends HttpServlet
        private long modifiedTime ;
        init()
            modifiedTime=System.timeMilliSeconds /1000*1000;
        //service method automatically calls getLastModified() for the conditional GET
        long getLastModified()
             return modifiedTime;
    {code}
    How I can achieve the same in JSP ?
    Is this work for POST method?
    Is refreshing the browser submits page with GET or POST ?
    Please help me understanding these and the solution for the above using JSP.
    Thanks in advance.{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Try to set "Last-Modified" response header via setDateHeader method.

  • How can I set Response Queue for standalone client using JMS Jax-RPC ?

    Hi,
    I am developing a standalone client for a web service running on a Weblogic 10.3 server using JMS transport. The response seems to be placed in JMSServer!JMSServer.TemporaryQueue0 when I try to test the application.
    The request xml created:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <content>
        <entry type="1">
            <textMessage fromQueue="true" JMSTimestamp="1285343150328" JMSReplyToDomain="1" JMSReplyTo="JMSServer!JMSServer.TemporaryQueue1" JMSRedelivered="false" JMSPriority="4" JMSMessageID="ID:&lt;520181.1285343150328.0&gt;" JMSExpiration="0" JMSDestination="SystemModule!demoQueue" JMSDeliveryMode="2">
                <headerProperty type="java.lang.String" value="text/xml; charset=utf-8" name="_wls_mimehdrContent_Type"/>
                <headerProperty type="java.lang.String" value="&quot;http://oracle/communications/platform/demo/webservices/rpc/secure/gen/getPhoneList&quot;" name="_wls_mimehdrSOAPAction"/>
                <headerProperty type="java.lang.String" value="/DemoWebServices/DemoWebServicesJMS" name="URI"/>
                <text>&lt;env:Envelope xmlns:env=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;env:Header/&gt;&lt;env:Body&gt;&lt;gen:lastName xmlns:gen=&quot;http://oracle/communications/platform/demo/webservices/rpc/gen&quot;&gt;8&lt;/gen:lastName&gt;&lt;/env:Body&gt;&lt;/env:Envelope&gt;</text>
            </textMessage>
        </entry>
    </content>On the application server I have configured a Response Queue that I would like my application to use. The client stubs where generated using the ant Task: weblogic.wsee.tools.anttasks.ClientGenTask.
    Standalone client code snippet:
          DemoWebServices_Impl service = null;
          try {
              service = new DemoWebServices_Impl(wsdl);
          } catch (ServiceException e) {
              e.printStackTrace();
          DemoWebServicesPortType port = null;
          //create credential provider and set it to the Stub
          try {
              port = service.getDemoWebServicesJMSPort();
          } catch (ServiceException e) {
            e.printStackTrace();
          PhoneList response = null;
          try {
              response = port.getPhoneList("8");
          } catch (RemoteException e) {
              e.printStackTrace();
          if(response != null) {
            for(Phone aPhone : response.getPhone()) {
                System.out.println("aReturned Phone number is:  " + aPhone.getPhoneNumber());
          }Would you please help me with modifying the client code to define which Queue the web service response should be placed in? setQueue() of the JMSTransportInfo class did not do the trick. Please help....
    Thanks,
    Sajitha
    Edited by: Sajitha on Sep 24, 2010 12:29 PM
    Edited by: Sajitha on Sep 27, 2010 8:44 AM

    Hi,
    I am developing a standalone client for a web service running on a Weblogic 10.3 server using JMS transport. The response seems to be placed in JMSServer!JMSServer.TemporaryQueue0 when I try to test the application.
    The request xml created:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <content>
        <entry type="1">
            <textMessage fromQueue="true" JMSTimestamp="1285343150328" JMSReplyToDomain="1" JMSReplyTo="JMSServer!JMSServer.TemporaryQueue1" JMSRedelivered="false" JMSPriority="4" JMSMessageID="ID:&lt;520181.1285343150328.0&gt;" JMSExpiration="0" JMSDestination="SystemModule!demoQueue" JMSDeliveryMode="2">
                <headerProperty type="java.lang.String" value="text/xml; charset=utf-8" name="_wls_mimehdrContent_Type"/>
                <headerProperty type="java.lang.String" value="&quot;http://oracle/communications/platform/demo/webservices/rpc/secure/gen/getPhoneList&quot;" name="_wls_mimehdrSOAPAction"/>
                <headerProperty type="java.lang.String" value="/DemoWebServices/DemoWebServicesJMS" name="URI"/>
                <text>&lt;env:Envelope xmlns:env=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;env:Header/&gt;&lt;env:Body&gt;&lt;gen:lastName xmlns:gen=&quot;http://oracle/communications/platform/demo/webservices/rpc/gen&quot;&gt;8&lt;/gen:lastName&gt;&lt;/env:Body&gt;&lt;/env:Envelope&gt;</text>
            </textMessage>
        </entry>
    </content>On the application server I have configured a Response Queue that I would like my application to use. The client stubs where generated using the ant Task: weblogic.wsee.tools.anttasks.ClientGenTask.
    Standalone client code snippet:
          DemoWebServices_Impl service = null;
          try {
              service = new DemoWebServices_Impl(wsdl);
          } catch (ServiceException e) {
              e.printStackTrace();
          DemoWebServicesPortType port = null;
          //create credential provider and set it to the Stub
          try {
              port = service.getDemoWebServicesJMSPort();
          } catch (ServiceException e) {
            e.printStackTrace();
          PhoneList response = null;
          try {
              response = port.getPhoneList("8");
          } catch (RemoteException e) {
              e.printStackTrace();
          if(response != null) {
            for(Phone aPhone : response.getPhone()) {
                System.out.println("aReturned Phone number is:  " + aPhone.getPhoneNumber());
          }Would you please help me with modifying the client code to define which Queue the web service response should be placed in? setQueue() of the JMSTransportInfo class did not do the trick. Please help....
    Thanks,
    Sajitha
    Edited by: Sajitha on Sep 24, 2010 12:29 PM
    Edited by: Sajitha on Sep 27, 2010 8:44 AM

  • Problem while setting response header in a filter

    Hi,
    I am intercepting response in a filter and trying to modify the response header, so that my subsequent class would get the header in request .
    Somehow i don't get the header in request. I don't know whats going wrong.
    I have few more filters other than the one in which i m modifying the response header.
    I change the response header before calling doFilter() method.
    Where am i going wrong ?

    The subsequent servlets and filters will get the same request that the first filter has. The passing to the next servlet is via a method call.

  • Attribute sharing before setting response

    Hello, I have a problem, because I use Session-attributes to share information between servlets, but when I want to read the attributes before the response has returned to the browser the attributes haven't been refreshed.
    How should I fix this problem? This is the code:
    RequestDispatcher disp;
    disp = req.getRequestDispatcher("login");
    if (disp != null)
         disp.include(req, res);then in the called servlet I put an attribute in the session called user and I try to read it in the dispatcher
    HttpSession ses = req.getSession();
    String theUser = (String) ses.getAttribute("user");like that, but before the response is returned this value is 'null'...
    How can I fix this problem, or do it in another way?

    are you sure you want to keep it in the session? I use the servlet dispatching to jsp method all the time and use a lot of
    request.setAttribute("servlet.created.object",obj)
    request.getAtrribute("servlet.created.object")
    this way you don't waste memory as in this obj only exists for the lifecycle of this request.
    what you are trying to do should work so i'm not sure why. I also build user objects through login servlets and add them to the session and then have the jsp use that object in the dispatch. The only thing that ever causes problems with that is having browser cookies disabled. If cookies are being blocked then no session variables will work.
    Hope that's some help, graeme.

  • Response object in JSP Dyn page

    Hi SAP EP Gurus,
    I want to use response.setStatus() mehtod in jspdynpage but it is not working as expected. I am able to use other methods of response object like response.write().
    As per my knowledge if i set response.setStatus(200) is should send error to client but it is not seding error.
    It is working as same for both response.setStatus(200) and response.setStatus(500).
    Is there any special way to use response.setStatus() in portal? It is working as expected in normal jsp application.

    I tried but had no luck. Below is my JSPDYNPAGE code...
    <%@ page import="javax.servlet.http.HttpServletResponse" %>
    <%@ page import="com.sapportals.portal.prt.component.IPortalComponentRequest,com.sapportals.portal.prt.component.IPortalComponentResponse"%>
    <HTML>
         <head>
         </head>
         <body>
    <%
    IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
    HttpServletResponse servletResponse = request.getServletResponse(true);esss
    servletResponse.setStatus(500);
    %>
              </body>
         </HTML>
    It is not working showing portal run time error

  • Proxy authontication popup for Https is not getting displayed

    Hi,
    We have proxy server in java, and it should ask for the authentication, while using old versions of IE (IE6), opera we get proper proxy authentication prompt for Https as well as Http request.
    But with the new version of browser IE8, Firefox 2, ... 3 we are not getting the Proxy authentication prompt for the Https request only (for http its working fine)
    Actually the proxy server ask for authentication for the every first request only, but if the first request is Https then it fails with 407 error, as per the logic whenever we set response.setStatus("407"); response.setMessage("Proxy authentication required"); it should prompt for the proxy authentication and its working fine for old browsers and for Http request but its not working for new browser with Https request
    Could you please provide some information on how to achieve proxy authentications for Https and new versions browsers.
    Following are the code used for it
    /*ResponseProcessor.java*/
         public static Response createResponse(ScriptableConnection connection, String message) {
              Response response = new Response();
              Request request = connection.getRequest();
              response.setRequest(request);
              if (message.equals(SPConstants.TECHNICAL_ISSUES)) {
                   response.setContent(message.getBytes());
              if (message.equals(SPAuthorizationConstants.INVALID_CREDENTIALS)) {
                   //response.setVersion(request.getVersion());
                   response.setHeader("Proxy-Authenticate", "Basic");
                   response.setStatus("407");
                   response.setMessage("Proxy authentication required");
                   if (request.getHeader("Proxy-Authorization") != null) {
                        response.setContent(message.getBytes());
                   return response;
              return response;
    /*ConnectionHandler.java */
    public void run() {
    String authorizationStatus = RequestProcessor.checkUserPreRequiste(request,user,ticket,statusVisitor); //SP CODE
                        if(authorizationStatus.equals(SPAuthorizationConstants.USER_IS_AUHTORIZED)) { //SP CODE
                                 try {
                                      response = hc.fetchResponse(request);
                                      if (response.getRequest() != null)
                                           request = response.getRequest();
                                                 }catch........
                       } finally {
                   try {
                        if (_clientIn != null)
                             _clientIn.close();
                        if (_clientOut != null)
                             _clientOut.close();
                        if (_sock != null && !_sock.isClosed()) {
                             _sock.close();
                   } catch (IOException ioe) {
                        _logger.warning("Error closing client socket : " + ioe);
    .......Thanks in advance,
    Sachin

    Hi
    Follow the steps
    In your current view where you create your Popupwindow; create a model attribute name "popWin" of type IWDWindow;
    In code;after creating the popup window assign window object to the context element
    IWDWIndow window = WDComponentAPI.getWindowManager().createWindow( WindowInfo, true);
    wdContext.currentContextElement.setpopWin( window);
    At the Popup window view; create a model attribute name popWin of type IWDWindow and map it with the one that created before.
    set the code on btnaction
    IWDWindow popwin = (IWDWindow)wdContext.currentContextElement().getPopWin();
    popwin.destroyInstance();
    This will work
    Regards
      - Vinod
    Edited by: Vinod V on Mar 3, 2008 7:21 PM

  • Setting the status code on 404

    Hi All,
    I have my web.xml file pointing 404 errors to /404.jsp on my web server (Apache/Tomcat).
    The code for 404.jsp is
    <%
    // Set the header response to a 404 and no-caching
    response.setStatus(response.SC_NOT_FOUND);
    response.setHeader("Cache-Control","no-cache");
    %>
    <jsp:include page="/404message.jsp"/>
    404message.jsp contains html and some other jsp scriptlets to display a nicely formatted error page that fits with the look and feel of the web site I am currently working on. I have to set the status like this otherwise the 404 error returns a response of 200 which is no good for the statistics program we run on the site.
    It all seems to work wonderfully except that in the localhost log for tomcat I get the following exception even though everything seems to work fine.
    2005-04-21 16:11:12 ErrorDispatcherValve[alligator]: Exception Processing ErrorPage[errorCode=404, location=/404.jsp]
    java.lang.IllegalStateException: Cannot reset after response has been committed
    at org.apache.catalina.connector.ResponseBase.reset(ResponseBase.java:789)
    at org.apache.catalina.connector.HttpResponseBase.reset(HttpResponseBase.java:812)
    and so on....
    Anybody point me in the right direction on this, any help much appreciated??
    Cheers,
    Beno..

    Just wanted to bring this one back to the front as had a zero response.
    Anyone shed any light on it for me??
    Cheers,
    Beno..

  • Error: response does not start with HTTP

    hi,
    i am using a MIDP class to send a string to a java servlet which then returns a .gif image. the string is being successfully to the servlet, but an exception is being thrown when the image is being sent back.
    java.io.IOException: response does not start with HTTP it starts with: GIF89aï4
    at com.sun.midp.io.j2me.http.Protocol.readResponseMessage(Protocol.java:2166)
    at com.sun.midp.io.j2me.http.Protocol.finishRequestGetResponseHeader(Protocol.java:1934)
    at com.sun.midp.io.j2me.http.Protocol.sendRequest(Protocol.java:1598)
    at com.sun.midp.io.j2me.http.Protocol.sendRequest(Protocol.java:1517)
    at com.sun.midp.io.j2me.http.Protocol.openInputStream(Protocol.java:484)
    my code is as follows in the midp class :
    HttpConnection c = null;
    InputStream is = null;
    StringBuffer sb = new StringBuffer();
    String url="http://localhost:8090/ProjectServer/createMap";
    url=url+"?Source="+src+"&Destination="+dest;
    try {
    c = (HttpConnection)Connector.open(url,Connector.READ_WRITE, true);
    c.setRequestMethod(HttpConnection.GET); //default
    //is = c.openDataInputStream();
    is = new DataInputStream(c.openInputStream()); //openInputStream(); // transition to connected!
    Image im=null;
    try
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = is.read()) != -1)
    bStrm.write(ch);
    // Place into image array
    byte imageData[] = bStrm.toByteArray();
    // Create the image from the byte array
    im = Image.createImage(imageData, 0, imageData.length);
    finally
    // Clean up
    if (is != null)
    is.close();
    the code in the servlet is as follows :_
    ServletContext sc = getServletContext();
    // Get the MIME type of the image
    String mimeType = sc.getMimeType("route.gif");
    if (mimeType == null) {
    sc.log("Could not get MIME type ");
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    return;
    // Set content type
    response.setContentType(mimeType);
    // Set content size
    response.setContentLength((int)file.length());
    // Open the file and output streams
    FileInputStream in = new FileInputStream(file);
    OutputStream outstream = response.getOutputStream();
    // Copy the contents of the file to the output stream
    byte[] buf = new byte[1024];
    int count = 0;
    while ((count = in.read(buf)) >= 0) {
    outstream.write(buf, 0, count);
    in.close();
    outstream.close();
    il be immensely grateful if some1 cud tell me whre i am gng wrong.
    thnx,
    nev

    Hi, I�m trying to do the same as above, get MP3 from a Shoutcast server.
    I got the same fault ("response does not start with HTTP it starts with: ICY") when I tried to open an HttpConnection as bellow:
    ============================================
    HttpConnection conn = (HttpConnection) Connector.open("http://64.236.34.196/stream/1074");
    Then I tried to open a socket connection as bellow:
    ======================================
    SocketConnection conn = (SocketConnection) Connector.open("socket://64.236.34.196:80");
    String get = "GET /stream/1074 HTTP/1.1";
    DataOutputStream os = conn.openDataOutputStream();
    os.writeUTF(get);
    InputStream is = conn.openInputStream();
    But then I got the following error:
    =========================
    java.lang.SecurityException: Target port denied to untrusted applications
    Could someone help me to find out what is going on?
    Thanks a lot!

Maybe you are looking for