How to test if a image file exists???

Hi ppl,
heres my problem...im using servlets and jsp and i only ever want to access the jsp file from a redirect in the servlet. Problem arises however if the user trys to access the jsp file directly in which case all the relative links on the page are no longer in the same context as if they were accessed via the servlet.
i wanna have some kind of test on my jsp page which displays an error page if the user has access the page directly but im not sure the best way to go about this.
i was thinkin about tryin to determine if an image file exists using a relative link...in which case if the relative links where off then it wouldnt.
Any suggestions on the best way to do this...or if there might be a better way to test such a case?
any advice much appreaciated.
Mycall

I would suggest moving all jsp's that you dont want the user to have direct access to under the WEB-INF directory. This way they would only be able to access it through your servlet.
Hope this helps

Similar Messages

  • How to test an image file existing or not

    Hi Everyone,
    I want to test whether an image file exists or not before setting the url of an image component in JSF to it. Following is my code:
    File testFile = new File(image_path + "/p1.jpg");
    if(testFile.exists()){
    info("file exists");
    }else{
    info("file not exists");
    this.myImage.setUrl(image_path+"/p1.jpg");
    Althoug the p1.jpg can be linked to myImage, the existence test always fails. That is, I got the message "file not exists" even though it is already displayed.
    What did I do wrong?
    Thanks in advance,
    Message was edited by:
    field

    File testFile = new File(image_path + "/p1.jpg");Is image_path an absolute path or relative path?

  • Spry:if image file exists?

    Hi,
    is there a easy way to test if an image file exists on the server? I try to generate dynamic html listing names and pictures. The names (and other info) arein a xml file. For some, images exist on the server as name.jpg file. I'd like to check with spry if name.jpg file exist and if take it as picture, if not use a general placeholder.
    thanks for any hlep,
    thorsten

    Hi Ben,
    thanks for your time and effort helping. I'd really appreciate this.
    How is the XML-file compiled eg from a database or coded by hand
              I use both on my web site and It would be nice if the solution would work both
                   - with a query send to our institutes phone book. Results are in xml format
                   - and a local xml file, that has been edited by hand.
    Is there a serverside program you use eg PHP, ASP, Coldfusion
              I can use PHP or javascript, but php does not work in combination with server-side-includes that we use on our apache web server. I'd prefer javascript, because those script run on any page, even if SSI is used.
    Have you considered using an HTML table to retrieve the info instead of using XML
              No yet, because also the local xml file is basically identical to the query output. I just add some fields manually to the local xml file. (So I could add a "picture" entry, but this solution would not work with the xml online query).
    Is there anywhere where I can view your code
              The page is already online, the goal is to eliminate the non-existing picture links. This page queries a local xml file
              http://lch.web.psi.ch/webcontent/EduTeach/students.html
              I did a similiar thing using php on other pages of the site. This page queries a phonebook database using the xml output. It is written in php, which does not work with our server when SSI is used. The workaround is to include a html page generated by a php scirpt using iframe. I'd really would love to replace this php script by a spry/javascirpt combination.
              http://lch.web.psi.ch/webcontent/research/surface/Gruppe.html
    I attach the html file and php file for the two pages. Thanks, best, t.

  • How to get and display image file through servlet

    If I've got a jpg file on the server..
    How can I use servlet to return that image via the following calling method
    /displayfile?filename=image.jpg
    the image.jpg in the server will return
    I know that I need to set the content type to image/jpeg
    after that, how can I return the image file to browser?

    - Get the "file" Parameter from the URL QueryString
    - check if the File specified exists on your filesystem
    - read in the jpg from the file (best would be binary)
    - set the right Mime Type (as you already wrote)
    - write the filecontent to the ServletOutput as you would do with any other content
    - that's it.

  • How can i upload a image file to server by using jsp or servlet.

    Hi,
    I m gurumoorthy. how can i upload a image file to server by using jsp or servlet without using third party API. pls anyone send me atleast outline of the source code.
    Pls send me anyone.
    Regards,
    Gurumoorthy.

    I'm not an applet programmer so I can't give you much advice there.
    If you want to stream the file from the server before it's entirely uploaded, then I don't believe you can treat it like a normal file. If you're just wanting to throw it up there and then listen to it, then you can treat it like a normal file.
    But again, I'm not entirely certain. You might be able to stream the start of the file from the server while you're still uploading the end of it, but it probably depends on what method you're using to do the transfer.

  • How to test the simple .java file in cactus

    dear friends,
    i have use the junit first time .And i am working in weblogic8.1 so i have use cactus .But i face the problem to use it.
    1. how to test the simple .java file in cactus.
    2.how to run the cactus in weblogic 8.1.

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • A how-To guide about splitting import files exists?

    Hi All,
    in his Webinar https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/409e4529-adbc-2a10-4d9b-e8fade570414
    Klaus David said a "A how-To guide about splitting import files exists" (Page 20).
    Can anybody tell me where to find this guide?
    Please mail to becker.roman ( at ) web . de
    Best regards
    Roman

    I found the link here, if you are still looking.
    I didnot check the contents yet but the title says
    MDM 5.5 SP06 - IT Scenario Configuration Guide -
    https://websmp202.sap-ag.de/~sapidb/011000358700001119482007E
    Thanks
    Satya

  • How can i display a image file which is placed in the applications server

    Hi all,
    Can any one help me how can I display a image file which is present in the application server.
    With regards,
    M.Ramana Murthy

    hi,
    *& Form TOP_OF_PAGE
    * text
    FORM F_TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = IT_LISTHEADER
    i_logo = Logo name
    * I_END_OF_LIST_GRID =
    ENDFORM. "TOP_OF_PAGE
    rgds
    Anver

  • How to locate the correct image file before reading/saving it

    Hi,
    I would like to find out how to copy/save/read image files from certain website in Java, particularly to locate the right one from various relative URL links on the same website. Below is an example to look at:
    On the main web page
    By selecting (http://www.abc.com/Public/Details.aspx?adid=2007103609) on a tiny camera icon that consist of source code (<td class="even"><a target="_blank" href="http://www.abc.com/Public/Details.aspx?adid=2007135110"><img src="/images/camera.gif" width="19" ...></a></td>) directed me to another page with the actual photo.
    The source code of this secondary page where the photo is located are as follows:
    <script language="JavaScript" type="text/javascript"><!--
    </script>
    <style type="text/css">@import url("http://fdimages.def.com.au/cui/netstrip-20050427.css");</style>
    <div id="networkStripTop">
    <a href="http://www.def.com.au/" onclick="linktop(this);" target="_top"><img src="http://fdimages.def.com.au/cui/digital.gif" height="17" width="95" class="logo" alt="DEF Digital" /></a>
    <div class="links">Any suggestion would be much appreciated.
    Many thanks,
    Jack

    Hi All,
    Could someone give me a hand with suggesting on how to locate the correct links (from multiple web pages) of the image file? I still could not proceed further on this issue.
    There is no problem with saving/reading the file once it is accurately identified.
    Please move it to the Java Technology & XML forum if it is not already in it.
    Many thanks,
    Jack

  • How to add, JS and image files in portalapp.xml

    Hi All,
    I was trying to implement multiple level hover detailed navigation in iview for which I got couple of css scripts from web which include javascripts.
    I placed these files in respective folders and their reference in header.jsp but when the iview is rendered in browser the reference is changing to .htm
    So please help me out how to place these script / image files in PAR file and their reference in portalapp.xml & header.jsp.
    Thanks in advance,
    Sai Krishna.

    1) The CSS file you have , save as "jsp" file and please place in the jsp folder.
    suppose your jsp is header.jsp and your css file is header_style.jsp
    include the css jsp - header_style.jsp in header.jsp like
    <%-- an include clause for css file --%>
    <%@ include file="header_style.jsp" %>
    2) All your images , please place in the "images" folder.
    3) To access the images use like below: in CSS file (jsp)
    in header_style.jsp
    yourimage: url(<%=mimeUrl%>/images/Border.gif);
    in header.jsp
    <%
    String mimeUrl = componentRequest.getWebResourcePath();
    %>
    4) more info for creating the hover menu read this blog
    https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4913
    Hope this will help you.

  • How can I upload a (image) file through an applet ?

    How can I upload a (image) file through an applet ?

    have a look at http://www.haller-systemservice.net/jupload/
    i'm using Apache Jakarta HTTPClient to create a new HTTP connection to the webserver and sending a new POST request, which holds the image file. (So it's RFC1867 conform)
    there is also an open source implementation of such an applet on sourceforge. it's also called JUpload, but i think it's not maintained any more.

  • How to Check Images File Exist? in different server

    Hi,
    I have 10 different coldfusion server.
    for example 9 server is for the web application site - for
    example
    http://myserverone/studentweb
    the other one is for images website, just for displaying
    student picture - for example
    http://myserverimage/studentpicture.
    the purpose of this website is to display student picture
    that i store as gif files.
    from my studentweb website i will call the images from
    studentpicture website as source for my image placeholder.
    for example this is my code i'm calling form
    http://myserverone/studentweb
    website:
    <img src="
    http://myserverimage/studentpicture/#studentnumber#.gif"
    alt="" name="studentpicture" width="160" height="200">
    my problem is, if there is no specific student picture in my
    studentpicture website, then the placeholder will display an X (
    mean the images not found )
    how do i prevent the X to display?
    how do i using coldfusion or any kind of way to check if the
    images exist on that website ( different server ), so if the images
    is not found, i can display a default images? i can do this if i'm
    calling the website in the same server, but not using a different
    server.
    this is like using other website images for your own personal
    website and sometimes the owner delete the images from their
    website, and i want to display my own images if that images been
    removed from the source website.
    anyone have done this before?
    thanks for suggestion and guide...
    haire

    1. Use CFHTTP with method="HEAD".
    2. See, if the HTTP status code is 200.
    The head-method is of course more efficient, as it doesn't
    need to "get" the message body. However, a status code of 200 is
    possible even when the requested image file is no longer on the
    server.

  • How to embed/show an image file (.jpeg or .jpg or .png) into a Oracle 10g report file (.rdf)

    Hi All,
    Morning , have an urgent requirement and need some guidance regards this.
    we are currently having an existing Oracle 10g reports file (.rdf)  lets say with name : Testing1.rdf .
    The report output is getting generated in a pdf format . it opens up in a pdf format..
    Now we want to embed an image file lets say : (logo.jpeg or logo.gif  ) into the report output..at run time the image from the image file should show up in the report output.
    Could someone please help as to how this could be achieved..and what approach we could follow for this...
    with regards
    Thanks as always !!

    Hi All,
    Morning ...just a follow up question to this original post : embedding the image files at runtime into an Oracle Report..
    We were able to achieve this by entering the folder location where the image files are place on the server in the REPORTS_PATH env variable in the report.sh file.
    Then we update this filename like file1.jpg into a table and from there we fetch this in the Oracle Reports data model directly.
    for The layout field we select the option as Image.
    All this works fine..
    Issue : The resolution of the embedded image in the generated report output is very low ...means the image appears there but it is not very clearly visible ..is there any way we could improve the IMAGE RESOLUTION in the report output....?????
    With regards

  • How to check if a specific file exist and which exit code to use ?

    Hi, First I'm not a scripting guy and I know almost nothing about VB scripting.
    I have a deployment of 6 tasks and I want to make sure that step # 2 will not be process if it failed in step #1, and so on for the 6 task.
    To do this, i have to run a vb script before installation or uninstalltion on each steps
    I'm trying to use a script (not from me) that i have modified for pre-uninstallation of software and also post-installation of the software.
    Pre-uninstallation: The script will look if the specified "exe" exist on the server and if so, than it will run the msiuninstall "application_name".
    If the uninstallation is successful, the post-installation script will check if the "exe" file exist again on the server, and it shouldn't find it (because it was deleted from the uninstallation), than it will return an exit code of successful
    to run the next process.
    Here an example:
    Step 1: Uninstall "Software#1" with msiuninstall Software#1.exe command
    Step 2: Uninstall "Software#2" with msiuninstall Software#2.exe command
    Step 3: Install "Software #3"with an .exe extension
    Step 4: Re install "Software #2" with an .msi extension
    Step 5: Re install "Software #1" with a .msi extension.
    Step 6: Send email to confirm the deployment is successful
    So i need to validate that step #2 will not process step #3 if it failled on # 2. It need to validate if the file exist before and after.
    At the end, Step 6 should send an email to confirm that the 6 steps of the deployment was completed without errors.
    Any idea how to do it ?
    Many many thanks for all the help !
    A desperate guy :)
    This is what i have
    'This script will look if an .exe file exist for a specific application.
    '=============================================================================================
    path = WScript.Arguments.Item(0)
    set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(C:\Inetpub\wwwroot\Enterprise\EnterpriseWS\web.config) = true then
        exitCode = 0
    else
        exitCode = 1
    End If
    Wscript.Quit exitCode

    Since you are not a scripting guy here is a very good place to start:
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    ¯\_(ツ)_/¯

  • How use PHP to read image files from a folder and display them in Flex 3 tilelist.

    Hello. I need help on displaying images from a folder dynamically using PHP and display it on FLEX 3 TileList. Im currently able to read the image files from the folder but i don't know how to display them in the TileList. This is my current code
    PHP :
    PHP Code:
    <?php
    //Open images directory
    $imglist = '';
    $dir = dir("C:\Documents and Settings\april09mpsip\My Documents\Flex Builder 3\PHPTEST\src\Assets\images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "filename: " . $file . "\n";
    $dir->close();
    ?>
    FLEX 3 :
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="pic.send();">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.rpc.events.ResultEvent;
    public var image:Object;
    private function resultHandler(event:ResultEvent):void
    image = (event.result);
    ta1.text = String(event.result);
    private function faultHandler(event:FaultEvent):void
    ta1.text = "Fault Response from HTTPService call:\n ";
    ]]>
    </mx:Script>
    <mx:TileList x="31" y="22" initialize="init();" dataProvider = "{image}" width="630" height="149"/>
    <mx:String id="phpPicture">http://localhost/php/Picture.php</mx:String>
    <mx:HTTPService id="pic" url="{phpPicture}" method="POST"
    result="{resultHandler(event)}" fault="{faultHandler(event)}"/>
    <mx:TextArea x="136" y="325" width="182" height="221" id="ta1" editable="false"/>
    <mx:Label x="136" y="297" text="List of files in the folder" width="182" height="20" fontWeight="bold" fontSize="13"/>
    </mx:Application>
    Thanks. Need help as soon as possbile. URGENT.

    i have made some changes, in the php part too, and following is the resulting code( i tried it, and found that it works.):
    PHP Code:
    <?php
    echo '<?xml version="1.0" encoding="utf-8"?>';
    ?>
    <root>
    <images>
    <?php
    //Open images directory
    $dir = dir("images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "<image>" . $file . "</image>"; // i expect you to use the relative path in $dir, not C:\..........
    //$dir->close();
    ?>
    </images>
    </root>
    Flex Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="callPHP();">
    <mx:Script>
    <![CDATA[
    import mx.rpc.http.HTTPService;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var arr:ArrayCollection = new ArrayCollection();
    private function callPHP():void
    var hs:HTTPService = new HTTPService();
    hs.url = 'Picture.php';
    hs.addEventListener( ResultEvent.RESULT, resultHandler );
    hs.addEventListener( FaultEvent.FAULT, faultHandler )
    hs.send();
    private function resultHandler( event:ResultEvent ):void
    arr = event.result.root.images.image as ArrayCollection;
    private function faultHandler( event:FaultEvent ):void
    Alert.show( "Fault Response from HTTPService call:\n " );
    ]]>
    </mx:Script>
    <mx:TileList id="tilelist"
    dataProvider="{arr}">
    <mx:itemRenderer>
    <mx:Component>
    <mx:Image source="images/{data}" />
    </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>
    </mx:Application>

Maybe you are looking for