Forcing a response

Hi guys
I have a JFrame which under certain circumstances creates a new JFrame as a pop up warning message, the only problem is I can't find/think of a way to force the user to click the ok button in the warning Frame so that they can't simply return to or interact with the original JFrame.
Any hints or relivate tutorials would be appriciated
cheers Steve

cheers i'm new to swing/awt so dont realy know my way round yet!
thanks again steve

Similar Messages

  • How to force a responsive Edge animation to re-evaluate its container size?

    I have an Edge animation stage embedded in a relatively complex page, inside a container div whose width is set by media queries and which may or may not be faded out by $.fadeOut. I've figured out how to trigger playback, but the stage doesn't seem to be updating its estimate of the container's width regularly. Specifically, the stage will scale itself to its min-width (disappearing if there is no min-width) and get stuck there in a specific case when the container's container has been hidden then shown again. And even when the stage is visible and on screen, if I make the browser thinner then wider, it seems to scale itself down but never back up. These weird problems would both be explained if the stage wasn't consistently re-evaluating how large its container was.
    In that case - is there a way to force the stage to re-evaluate its container size using Javascript? Wasn't able to find anything in the documentation about this.
    Thanks!

    Hi, Chi-
    Funny you should mention this... I actually just posted a blog post about something very similar.
    https://blogs.adobe.com/edge/2013/09/05/floral-matchmaker-tutorial-3-hiding-and-showing-th e-game-board/
    You can put your responsive div in an iframe set to a certain % of your main page.
    -Elaine

  • Error while accessing Sales-force adapter response variable

    Hi,
    Using salesforce adapter we are creating an account. Based on the response planning to proceed the next flow. But while accessing success variable in the salesforce response. we are getting following exception:
    The <from> value is invalid. The result of from-spec is null. Either the from node value or the xpath query in the from node value was invalid. According to BPEL4WS spec 1.1 section 14.3, the from node value should not be empty. Verify the from node value at line number 104 in the BPEL source.
    But in flow trace(Audit trail) we are able to see response.
    Thanks,
    KANN

    Hi Anoo,
    you can use app_id,page id ,session in javascript function,see the code given below
    $v('pFlowId') // APP_ID
    $v('pFlowStepId') // APP_PAGE_ID
    $v('pInstance') // SESSIONEdited your code, try it.
    <script type="text/javascript">
    $( function() {
        $("#P1_ENG_PART1").autocomplete({
            source : function( request , response) {
                            data = getJParticipant(request.term);
                            response( data );
            focus  : function(event , ui){
                        event.preventDefault();
    function getJParticipant(key)
       // Here i want to check the App_session logic code and hence i had implmented which is not working.
           Can any one help me how we can resolve the below problem.
         if ($v('pInstance')) is not null then
          var ajaxRequest = new htmldb_Get( null , '&APP_ID.' , 'APPLICATION_PROCESS=GET_JPARTICIPANT' , 0);
       ajaxRequest.add( 'G_MX01' , key);
       ajaxResult = ajaxRequest.get();
       return ((ajaxResult.length>0)? ajaxResult.split( '~' ):null);
    end if;
    </script>Regards,
    Jitendra

  • HTTP Response Header code and message

    Hi all, i have a web service that return a JSON file, the scenario is syncronous like this: HT(CALL,SYNC) - Handover - dynamic
    Hi have the need to change the defaul behavior of the response headers, for example i whant to return:
    404 Not Found - ID not found.
    in my last atom i have this payload:
    xsl:attribute name="pltype">json</xsl:attribute>
    <io xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:com.sap.b1i.bizprocessor:bizatoms" pltype="json" xsi:schemaLocation="urn:com.sap.b1i.bizprocessor:bizatoms json_pltype.xsd">
    Where i can force the response to have a custom response code and message ?
    Thank you all

    I'm not sure if I got you right. Do you want to have another signature for printinfo()?
    The solution then is:
    public static void printinfo(String urlString) throws IOException, MalformedURLException {
      URL url = new URL(urlString);
    }

  • Wsrp-requireRewrite for URLs in resource response ?

    I'm using Portal 10.1.4 serving WSRP content from a
    portlet producer running on 10.1.3.2 (JDev embedded OC4J).
    I want to use an AJAX resource request to serve a fragment of
    portlet markup containing further portlet and AJAX URLs.
    URL rewriting for full page portlet rendering requests works fine,
    but I can't get a resource request served with WSRP URL rewriting.
    Here is my approach ... a resource request is sent from a portlet page
    using a URL that was created in in a full portlet request.
    The flag 'wsrp-requireRewrite=true' is WSRP encoded as '__ora_rewrite=1'.
    The Portal server presumably intercepts the request and stores the value of this flag,
    then sends the raw resource request to the resource servlet on the portlet producer
    (i.e. markup generated through a servlet context, not a portlet context).
    The new markup fragment contains URLs embedded between 'wsrp_rewrite' tags.
    The Portal server should intercept the response and rewrite the URLs,
    but it swallows the whole thing, and an empty response is returned to the client.
    Is wsrp-requireRewrite=true supposed to work for resource requests ?
    Any ideas what could be wrong ?
    Mik

    The problem was MIME type.
    I had assumed Portal server would rewrite any text responses,
    but it does not rewrite 'text/xml' data, in fact it sends it to the bit bucket !
    So you need to force the response Content-Type in the resource provider.
    The only valid rewritable types seem to be:
    'text/plain', 'text/html' and variants like 'text/html+xml'.
    The rewritten URLs will not be XML-escaped
    i.e. '&' parameter separator will not be escaped to '&amp;amp;' .
    So when doing AJAX updates you have to explicitly escape the URLs
    and invoke an XML parser in client-side JavaScript,
    rather than relying on the implicit mechanisms within XmlHttpRequest.
    Mik

  • MVC Web API json response truncated?

    I have an MVC 4 Web API in C# hosted in IIS 7
    Basically this service has a queue that has items enqueued every minute. I expose a GET method that allows for all the items in the queue to be returned in a json array.
    the queue is really this: Queue<List<CustomObject>> mQueue; then every minute a new list is enqueued.
    The max size of the queue is 50 (1 hour of data)
    the maximum count of a list in said queue is ~500 and minimum count is ~100. When I debug the api locally It will return all the elemnets in the queue no problem. only takes a couple seconds. The size of the json response (saved to disk) is ~10Mb.
    So I decided to host this service on a VM. I let it run for a while so the queue gets populated. then I make my request:
    http://somepoint:4328/AzureQueueService?view=Full
    I only get 1.30 - 1.32 mb of data back. Which equates to about 4 minutes worth of data! So the question becomes is there some setting in IIS that forces the response sent to be less than 2Mb? Maybe there is a similar setting in my webconfig? Or maybe IIS
    has created more than one instance of my service? Either way, I'm missing something here.

    What OS (including SP number) your service is running on? (both local and VM)
    Do you receive the same amount of data as specified in Content-Length header? Is your response a valid JSON (just having less data than expected), or it is really truncated?
    Where is your queue hosted? Is it just a static object inside IIS process, or somewhere out-of-process?
    How is it filled? By another method passing incoming data? Do you use thread synchronization when accessing the queue?
    IIS may have multiple worker processes per application, and each will have its own static queue (of course, if it is hosted in-process). Also IIS might recycle worker processes, so in-process data could be lost.

  • CQ5 Response Encoding

    Hi Folks,
    Does any one know whats default character encoding used by CQ5? (UTF-8, ISO-8859-1 etc)
    Does it depend on whats the encoding used when the file was stored, if so whats the default encoding CRXDE uses to store file?
    /etc/crxde/profiles/default/classpath.xml.xslt has following setting.. does it means anything in this case?
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    Thanks an in advance!
    - Adnan

    Hi Sham,
    Do you have a reference for any further information on how to set the default response encoding in the CQ / Day Servlet Engine?  I've been searching for a way to get CQ5 to return UTF-8 encoded responses (for all responses, not just POST), but not having any luck so far.
    In the jsp file I have:
    <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    And in the head of the html is:
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    But still get ISO-8859-1 in the response header (for a GET request):
    Content-Type:
    text/html;charset=ISO-8859-1
    It seems that CQ5 is still using the default encoding somehow.  Is it possible to change the default encoding to UTF-8, or do I need to implement a servlet filter to force the response encoding?  I'm using CQ5.5 SP2, if that makes any difference.
    Thanks,
    Ray

  • Force download of JPEG

    Hi,
    My servlet creates a JFreeChart with the writeChartAsJPEG function. The chart itself is created properly.
    I would like to allow the user to open or save the file via a dialog box, but IE recognises the file type and displays the chart in the browser.
    I have been searching the Internet for ages now and haven't found a solution to my problem.
    Do you have a solution to open the dialog box instead of displaying the chart in the browser?
    My code is the following:
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
    try {
    response.reset();
    ChartUtilities.writeChartAsJPEG(response.getOutputStream(), getChart(request), 500, 300);
    response.setContentType("application/force-download");
    response.setHeader("content-disposition","inline; filename=Injury_Data.jpg");
    } catch (Exception e) {e.printStackTrace();}
    I have tried, without any success, the following actions:
    - Replace "inline" per "attachment"
    - Replace ".jpg" per ".zzz" or deleting extension
    - Add response.setHeader("pragma","public")
    - All sorts of MIME type: "image/jpeg", "application/unknown", "application/stream", "application/octet-stream", etc...
    The problem is urgent now and i don't have any more leads to try and find a solution. Do you have any idea?
    Thanks,
    Christelle

    I am doing something similar and mine works... Try setting the response headers before outputting the image. The only other differences I see are capitilization (Content-Disposition), and using quotes (") around the filename.

  • Visual Studio download a document from a document libary and upload it to a jaxrs webservice in java

    I have created a custom ribbon action and a application page in visual studio. The user
    presses my ribbon in sharepoint and it calls the application page that in turn downloads that file. here is the code:
    namespace Save_to_PLM.Layouts.Save_to_PLM
    public partial class ApplicationPage : LayoutsPageBase
    protected void Page_Load(object sender, EventArgs e)
    if (Request.QueryString["file"] != null)
    DownloadDocument(Request.QueryString["file"].ToString());
    private void DownloadDocument(string fileName)
    SPSecurity.RunWithElevatedPrivileges(delegate()
    using (SPSite oSiteCollection = new SPSite(SPContext.Current.Site.Url))
    using (SPWeb mi_web = oSiteCollection.OpenWeb())
    string path = System.Web.HttpContext.Current.Server.MapPath(fileName);
    string name = System.IO.Path.GetFileName(path);
    Console.WriteLine(name);
    Microsoft.SharePoint.SPFile spFile = mi_web.GetFile(fileName);
    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType = "application/force-download";
    Response.AppendHeader("content-disposition", "attachment; filename=" + name);
    Response.BinaryWrite(spFile.OpenBinary());
    Response.End();
    But i want to http post that file to my jaxrs webservice in java. How do  i do that
    programmatically? I am very new .net i usually code in java.

    Hi,
    Here is a blog about how to call a Java EE Web Service from a .Net Client for your reference:
    http://blogs.msdn.com/b/bursteg/archive/2008/07/19/how-to-call-a-java-ee-web-service-from-a-net-client.aspx
    If you want to download a document from a Sharepoint library, we can use the REST API provided by SharePoint and use Apache HttpComponents in Java.
    http://www.rgagnon.com/javadetails/java-get-document-sharepoint-library.html
    About how to upload file using jaxrs webservice in C# code, I suggest you post it to C# or ASP.Net Forum, you will get more help and confirmed answers from there.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=csharpgeneral
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Name of exported PDF file

    <p>Hello,</p><p>I hope I&#39;m in the correct section and that someone will be able to help me.</p><p>I run a web application (within Weblogic 8.1 sp5) which allows the direct generation of reports in PDF.<br />Each report has a unique name and I want the PDF to open in my Web browser.<br />The problem I get is that the name of this PDF is not the one that I want.</p><p>As the export is always in PDF, I&#39;m using the ReportExportControl class.<br />When I use <font face="courier new,courier">setExportAsAttachment(false)</font> along with <font face="courier new,courier">setName(idReport)</font>, the name of the PDF when I click &#39;Save&#39; is the name of my jsp, not <font face="courier new,courier">idReport</font>.<br />When I use setExportAsAttachment(true), the name is not exactly idReport.</p><p>I also tried forcing the response header to specify the attachment name, without any success either.<br />Do someone have any idea ?</p><p>Here below a sample of my code :</p><font size="2"><p><font size="1"><font face="courier new,courier">ReportExportControl exportControl = <strong><font color="#7f0055">new</font></strong></font></font><font face="courier new,courier" size="1"> ReportExportControl();<br /></font><font face="courier new,courier" size="1">exportControl.setReportSource(reportSource);<br /></font><font size="1"><font face="courier new,courier">ExportOptions exportOptions = <strong><font color="#7f0055">new</font></strong></font></font><font face="courier new,courier" size="1"> ExportOptions();<br /></font><font color="#3f7f5f"><font face="courier new,courier" size="1">//exportControl.setExportAsAttachment(false); // this will open the file in the current window<br /></font></font><font size="1"><font face="courier new,courier">exportControl.setExportAsAttachment(<strong><font color="#7f0055">true</font></strong></font></font><font size="1"><font face="courier new,courier">); <font color="#3f7f5f">// this will open a &#39;save as&#39; popup<br /></font></font></font><font color="#3f7f5f"><font face="courier new,courier" size="1">//exportControl.setOwnForm(true);<br /></font></font><font size="1"><font face="courier new,courier">exportControl.setOwnPage(<strong><font color="#7f0055">true</font></strong></font></font><font face="courier new,courier" size="1">);<br /></font><font face="courier new,courier" size="1">exportControl.setName(idPackage);<br /></font><font face="courier new,courier" size="1">exportOptions.setExportFormatType(ReportExportFormat.PDF);<br /></font><font face="courier new,courier" size="1">exportControl.setExportOptions(exportOptions);<br /></font><font color="#3f7f5f"><font face="courier new,courier" size="1">// Assign Fields collection to the viewer<br /></font></font><font face="courier new,courier" size="1">exportControl.setParameterFields(parameterFields);<br /></font><font color="#3f7f5f"><font face="courier new,courier" size="1">// Disable database logon information request<br /></font></font><font size="1"><font face="courier new,courier">exportControl.setEnableLogonPrompt(<strong><font color="#7f0055">false</font></strong></font></font><font face="courier new,courier" size="1">);<br /></font><font color="#3f7f5f"><font face="courier new,courier" size="1">// Assign the connectionInfos to the viewer<br /></font></font><font color="#3f7f5f"><font face="courier new,courier" size="1">//exportControl.setDatabaseLogonInfos(connectionInfos);<br /></font></font><font face="courier new,courier" size="1">response.reset();<br /></font><font face="courier new,courier" size="1">response.setContentType(<font color="#2a00ff">"application/pdf"</font>);<br /></font><font face="courier new,courier" size="1">response.setHeader(<font color="#2a00ff">"Content-Disposition"</font>,<font color="#2a00ff">"inline;filename="</font> + idPackage + <font color="#2a00ff">".pdf"</font>);<br /></font><font size="1"><font face="courier new,courier">exportControl.processHttpRequest(request, response, getServletConfig().getServletContext(), <strong><font color="#7f0055">null</font></strong></font></font><font size="2"><font face="courier new,courier" size="1">);<br /></font><font face="courier new,courier" size="1">exportControl.dispose();<br /></font></font></p></font><p>Thanks alot for helping ;)</p><p>Bernard</p>

    <p> </p><p>The ReportExportControl specifies the header info, so it will not keep the values you set in code. Two options:</p><p>1. If you&#39;re using JRC XI Release 2 or newer, get the export using ReportClientDocument.getPrintOutputController().export(...) method.  You can then redirect the export output to the HTTP Response stream after specifying the header info as you&#39;re doing now.</p><p>2. If you need to use ReportExportControl, get the export format stream by passing processHttpRequest a &#39;fake&#39; HTTPResponse object that you create yourself.  Make the &#39;fake&#39; response return a &#39;fake&#39; ServletOutputStream that you create yourself, where you override the write(...) method to pass it to the &#39;real&#39; HTTP Response stream.  This way, you can throw out all the header info that ReportExportControl uses, and specify your own.</p><p>One thing - you have to be careful to ensure that your report pdf name represents a valid filename on every client OS that your page is being viewed.</p><p>TUeda </p>

  • Working Sample Code: File Download Servlet

    Pardon the cross-posting (Java Servlet Technology), but when I was researching this problem I found alot of people asking this question in here as well as in the servlet forum. So I thought this code would be helpful here too.
    Here is a complete working servlet for downloading virtually any type of file to a browser.
    It uses a file called application.properties to specify the location of the folder where the files to be downloaded reside. Of course you could modify this to allow the users to select the location as well.
    A sample URL to call the Servlet would look like this:
    http://localhost/website/servlet/DownloadAssistant?YourFileName.ext
    I tested this with varying filenames. It did have some issues if the file contained special characters like # symbol. This should be manageable however.
    Hope someone finds this useful.
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.zip.GZIPOutputStream;
    public class DownloadAssistant extends HttpServlet
    private static final String DIR = "dir";
    private String separator;
    private String root;
    public DownloadAssistant()
    Properties propFile = null;
    FileInputStream in = null;
    String JAVA_HOME = "C:\\jrun\\servers\\default\\filetest\\application.properties";
    // Get a handle on the peoperties file
    try{
    in = new FileInputStream(JAVA_HOME);
    propFile = new Properties();
    propFile.load(in);
    catch (IOException ignore){}
    separator = "/";
    // Get the directory from the application.properties file
    // e.g. C:\\Temp\\Files\\
    root = propFile.getProperty("app.directory");
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    processRequest(request, response);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    processRequest(request, response);
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    PrintWriter out = null;
    ServletOutputStream stream = null;
    GZIPOutputStream zipstream = null;
    Object obj = null;
    String s = "";
    //determine if there is a filename appended to the url
    // If so, then decode it
    s = HttpUtils.getRequestURL(request).toString();
    int i;
    if((i = s.indexOf("?")) > 0)
    s = s.substring(0, i);
    String s1;
    if((s1 = request.getQueryString()) == null)
    s1 = "";
    else
    //s1 = decode(s1);
    s1 = URLDecoder.decode(s1);
    // No filename, so set contentType and generate error message
    if(s1.length() == 0)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<p>Could not get file name ");
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Restriction while gaining access to the file
    if(s1.indexOf(".." + separator) > 0)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<br><br><br>Restrictions on filename");
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Try to get a handle on the file
    File file = new File(root + s1);
    // Couldn't get the file, return an error message
    if(file == null)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<p>Could not read file: " + s1);
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Either the file doesn't exist or it can't be read, return an error message
    if(!file.exists() || !file.canRead())
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html><font face=\"Arial\" size=\"+1\">");
    out.println("<p>Could not read file " + s1);
    out.print("<br>Reasons are: ");
    if(!file.exists())
    out.println("file does not exist");
    else
    out.println("file is not readable at this moment");
    out.println("</font></html>");
    out.flush();
    out.close();
    return;
    // Looks like we can read/access the file, determine its type
    String s2 = request.getHeader("Accept-Encoding");
    // Is this a zip file?
    boolean flag = false;
    if(s2 != null && s2.indexOf("gzip") >= 0)
    flag = true;
    flag = false;
    if(flag)
    response.setHeader("Content-Encoding", "gzip");
    response.setHeader("Content-disposition", "attachment;filename=" + s1);
    stream = response.getOutputStream();
    zipstream = new GZIPOutputStream(stream);
    downloadFile(root + s1, zipstream);
    zipstream.close();
    stream.close();
    // It's not a zip file so treat it as any other file
    else
    response.setContentType("application/force-download");
    response.setHeader("Content-disposition", "attachment;filename=" + s1);
    stream = response.getOutputStream();
    downloadFile(root + s1, stream);
    stream.flush();
    stream.close();
    }// end processRequest()
    // This method downloads the file to the browser
    private void downloadFile(String s, OutputStream outstream)
    String s1 = s;
    byte abyte0[] = new byte[4096];
    try
    BufferedInputStream instream = new BufferedInputStream(new FileInputStream(s1));
    int i;
    while((i = instream.read(abyte0, 0, 4096)) != -1)
    outstream.write(abyte0, 0, i);
    instream.close();
    catch(Exception _ex) { }
    }//end downloadFile()
    public void init(ServletConfig servletconfig)
    throws ServletException
    super.init(servletconfig);
    String s;
    if((s = getInitParameter("dir")) == null)
    s = root;
    separator = System.getProperty("file.separator");
    if(!s.endsWith(separator))
    s = s + separator;
    root = s;
    }//end init()
    }//end servlet()

    Yes - it is useful

  • Working Sample Code: FileDownload Servlet

    Here is a complete working servlet for downloading virtually any type of file to a browser.
    It uses a file called application.properties to specify the location of the folder where the files to be downloaded reside. Of course you could modify this to allow the users to select the location as well.
    A sample URL to call the Servlet would look like this:
    http://localhost/website/servlet/DownloadAssistant?YourFileName.ext
    I tested this with varying filenames. It did have some issues if the file contained special characters like # symbol. This should be manageable however.
    Hope someone finds this useful.
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.zip.GZIPOutputStream;
    public class DownloadAssistant extends HttpServlet
    private static final String DIR = "dir";
    private String separator;
    private String root;
    public DownloadAssistant()
    Properties propFile = null;
    FileInputStream in = null;
    String JAVA_HOME = "C:\\jrun\\servers\\default\\filetest\\application.properties";
    // Get a handle on the peoperties file
    try{                         
    in = new FileInputStream(JAVA_HOME);
    propFile = new Properties();
    propFile.load(in);
    catch (IOException ignore){}
    separator = "/";
    // Get the directory from the application.properties file
    // e.g. C:\\Temp\\Files\\
    root = propFile.getProperty("app.directory");
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    processRequest(request, response);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    processRequest(request, response);
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    PrintWriter out = null;
    ServletOutputStream stream = null;
    GZIPOutputStream zipstream = null;
    Object obj = null;
    String s = "";
    //determine if there is a filename appended to the url
    // If so, then decode it
    s = HttpUtils.getRequestURL(request).toString();
    int i;
    if((i = s.indexOf("?")) > 0)
    s = s.substring(0, i);
    String s1;
    if((s1 = request.getQueryString()) == null)
    s1 = "";
    else
    //s1 = decode(s1);
    s1 = URLDecoder.decode(s1);
    // No filename, so set contentType and generate error message
    if(s1.length() == 0)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<p>Could not get file name ");
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Restriction while gaining access to the file
    if(s1.indexOf(".." + separator) > 0)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<br><br><br>Restrictions on filename");
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Try to get a handle on the file
    File file = new File(root + s1);
    // Couldn't get the file, return an error message
    if(file == null)
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<p>Could not read file: " + s1);
    out.println("</html>");
    out.flush();
    out.close();
    return;
    // Either the file doesn't exist or it can't be read, return an error message
    if(!file.exists() || !file.canRead())
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html><font face=\"Arial\" size=\"+1\">");
    out.println("<p>Could not read file " + s1);
    out.print("<br>Reasons are: ");
    if(!file.exists())
    out.println("file does not exist");
    else
    out.println("file is not readable at this moment");
    out.println("</font></html>");
    out.flush();
    out.close();
    return;
    // Looks like we can read/access the file, determine its type
    String s2 = request.getHeader("Accept-Encoding");
    // Is this a zip file?
    boolean flag = false;
    if(s2 != null && s2.indexOf("gzip") >= 0)
    flag = true;
    flag = false;
    if(flag)
    response.setHeader("Content-Encoding", "gzip");
    response.setHeader("Content-disposition", "attachment;filename=" + s1);
    stream = response.getOutputStream();
    zipstream = new GZIPOutputStream(stream);
    downloadFile(root + s1, zipstream);
    zipstream.close();
    stream.close();
    // It's not a zip file so treat it as any other file
    else
    response.setContentType("application/force-download");
    response.setHeader("Content-disposition", "attachment;filename=" + s1);
    stream = response.getOutputStream();
    downloadFile(root + s1, stream);
    stream.flush();
    stream.close();
    }// end processRequest()
    // This method downloads the file to the browser
    private void downloadFile(String s, OutputStream outstream)
    String s1 = s;
    byte abyte0[] = new byte[4096];
    try
    BufferedInputStream instream = new BufferedInputStream(new FileInputStream(s1));
    int i;
    while((i = instream.read(abyte0, 0, 4096)) != -1)
    outstream.write(abyte0, 0, i);
    instream.close();
    catch(Exception _ex) { }
    }//end downloadFile()
    public void init(ServletConfig servletconfig)
    throws ServletException
    super.init(servletconfig);
    String s;
    if((s = getInitParameter("dir")) == null)
    s = root;
    separator = System.getProperty("file.separator");
    if(!s.endsWith(separator))
    s = s + separator;
    root = s;
    }//end init()
    }//end servlet()

    Instead of hardcoding the directory where the files are located, I keep that in a file called application.properties.
    there is a property there which looks like this
    app.directory=C:\\Temp\Files\\
    It's easier to change this rather than recompiling the servlet.
    I also use that file to hold things like the JDBC driver I will be using as well as other application specific properties I don't want to hardcode.
    HTH

  • Getting the Intended Target for a Request

    I now know how to set the target for a response:
    HttpServletResponse.setHeader("Window-target","myFrameName")
    My next question is how do I determine the intended target of the initial request, before I set it to something else with the above code? It doesn't seem to be in the header parameter list. Is there another source?

    There's no way to get the initial target from the request. That information isn't sent by the browser. :-/
    I didn't even know you could force the response to go in another window from the server-side. Most of the time, you know which window it's going to already, so you have the HTML <form> specify target="myFrameName", which forces the whole request to occur in another window.

  • Downloading a File with a Unicode File-name

    hello!
    I have a program under Tomcat
    this program has a JSP file with Links on different files
    that can be downloaded by the user
    on click to a certain link, a pop-up for save-as dialog will appear.
    the unicode file-name appears correctly on the save-as dialog box
    the save-as dialog box contains buttons such as
    Open, Save and Cancel
    the result is:
    Dialog-Display FileName- OK
    Open - NG
    Save - OK
    im using IE 6 sp1
    heres my code on the force-download
         response.setContentType("application/octct-stream;charset=UTF-8");
            response.setContentType("application/force-download");
         response.setHeader("Content-Disposition", "attachment;filename="
                    + downloadFileName  );

    already solved....................

  • HELP!! servlet stops working sometimes!!!

    Can somebody please tell me what is wrong with the following code. Im starting to think it might be my sql statements. The servlet works correctly, but every couple days, when I run the servlet, it displays a blank page, and i have to upload the class file to the server again, then the servlet works. This is happening to a couple of my servlets, and I posted the problem on here several times, and each time I thought the problem was fixed, but it is not.
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class byTown extends HttpServlet
    Connection con = null;
    Connection con2 = null;
    public void init (ServletConfig cfg)
    throws ServletException {
    super.init (cfg);
    try {
    Class.forName("org.gjt.mm.mysql.Driver");
    // Get Connection
    con = DriverManager.getConnection ("jdbc:mysql://localhost/comperry_main","myusername","mypassword");
    con2 = DriverManager.getConnection ("jdbc:mysql://localhost/comperry_main","myusername","mypassword");
    }catch(ClassNotFoundException E) {E.printStackTrace();}
    catch(SQLException e) {e.printStackTrace();}
    public void doGet (HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    // Have browser ignore cache - force reload
    // response.setHeader ("Expires",
    // "Mon, 01 Jan 1990 00:00:00 GMT");
    Statement stmt = null;
    ResultSet result = null;
    Statement stmt2 = null;
    ResultSet result2 = null;
    outline c=new outline();
    try {
    // Submit query
    stmt = con.createStatement();
    stmt2 = con2.createStatement();
    result = stmt.executeQuery ("SELECT town,phnumber from towns where 1");
    // Create output
    PrintWriter out = response.getWriter();
    out.print(c.header());
    while(result.next()) {
    result2 = stmt2.executeQuery ("SELECT COUNT(*) as mycount from business_info where (duplicateLink=-1 or duplicateyn=1) and (phone LIKE '%"+result.getString("phnumber")+"%' or Address1 Like '%"+result.getString("town")+"%' or Address2 Like '%"+result.getString("town")+"%') order by 'name'");
    result2.next();
    out.println("<a href=\"/servlet/myTown?ph="+result.getString("phnumber")+"\">"+result.getString("town")+" ("+result2.getInt("mycount")+" listings)</a><br>");
    result2.close();
    result.close();
    out.print(c.footer());
    out.flush();
    out.close();
    }catch(SQLException e){}
    finally {   
    try{
    if(result!=null)result.close();
    if(stmt!=null)stmt.close();
    if(result2!=null)result2.close();
    if(stmt2!=null)stmt2.close();
    }catch(SQLException e){e.printStackTrace();}
    public void destroy() {
    super.destroy();
    try{
    con.close();
    con2.close();
    }catch(SQLException e){e.printStackTrace();}

    hai,
    JDBC Socket Connection is very costly, because of which everybody use a concept of Pooling the Connection.
    The Instantiation of connection object itself takes more time and you never do that kind of coding like.
    Go to Google Type "Connection Pool" and download a simpler ConnectionPool Source code and use it.
    Or otherwise use the connection pool facility, if your server supports(The actual Impl/specifications are provided by sun , which is nothing but javax.sql.* packages), and I hope almost all javawebservers has a support to connectionPool, which are implmented according to Suns Specification( which would be the best,if u do).
    If you use the above code, You will definitely suffer in future.
    You should never close the connection, if you have written of your own connection pool (at any cost you should close result and statments).
    but if you are using built-in Servers ConnectionPool , then close() method on DataSource Object is more like returning connection to the pool back, rather closing the connection.
    You must make sure , that you are returning connections to the pool once after it is used(Normally , should be handled at finally blocks).
    (Make sure, your databse supports auto commit facility, if so , do commit and rollback properly without fail, if you had set the autocomit to "false")
    If you don't have any idea about Pooling, Please read on some good books
    I recommend you, even almost all Collections classes should be pooled , since they are very costly and the instantiation time is more.
    With Regards
    Lokesh T.C

Maybe you are looking for

  • No G/L account found in Account determination type KOFI

    Hello everyone, I have an issue with a billing document, it will not release to accounting. I think I know what the issue is, however I have no idea how to fix it. When I go into the billing document, and I run an "Account Determination Analysis" for

  • Financial Tax Register Report shows No Data Found

    Hi All, We are upgrading from 11.5.10 to 12.1.3, ofter upgrading to 12.1.3 when i running the Financial Tax Register Report it is showing No Data Found. Please reply me ASAP. Regards, Raju.

  • Missing part message in MIGO

    Hello, we have activated the missing part message in MIGO using transaction OMBC. All is working fine and we receive an notification in business workplace. The problem is that only one person receives the mail and we want that all MRP controllers get

  • ITunes 10.6.3 wont play music videos

    No music videos will play on my retina macbook pro.  Only the sound plays. This is only happening for music videos. mac os 10.8.1 with iTunes 10.6.3.  How do I fix this?  Why cant I play my music videos????????

  • German macbook keyboard

    i just bought a new white macbook for my girlfriend. she's german, so i'm wondering what options exist for replacing it with a german keyboard (that she could perhaps find at an apple dealer in germany). Which models of macbooks/ibooks use the same m