Not possible to get image & text in a servlet

Hi
i want to display a image and below to that wnat to display a text.But text is not displaying.Please refer the following code.
package com.Test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.NamingException;
public class imagetry1 extends HttpServlet{
   public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException{
     PrintWriter out = res.getWriter();
      try{
         // out.println("<h1> Drapes <hr> </h1>");
         FileInputStream fis = new FileInputStream("c:/hi/world.jpg");
         BufferedInputStream bis = new BufferedInputStream(fis);
         byte[] bytes = new byte[bis.available()];
         res.setContentType("image/jpeg");
         OutputStream os = res.getOutputStream();
         bis.read(bytes);
         os.write(bytes);
         String s1 = "Drapes";
         byte[] b1 = s1.getBytes();
         os.write(b1);
         res.setContentType("text/html" );
         out.println("<h1> Drapes <hr> </h1>");
      catch(IOException e){
}

Oh no.
* JSP/Servlet outputs HTML.
* Images in HTML are to be displayed using <img> tag.
* The 'src' attribute of the <img> tag expects a valid URL (yes, URL!!) to the image.
Clear?
OK, if you use a local file system path of the server machine instead of a public URL to the image in the 'src' attribute, then it is certainly not going to work. The HTML is been sent from the server machine to the client machine. The HTML is been parsed and evaluated at the client machine. Any URL's will be invoked to the server again, but any local file system paths will be invoked on the local file system of the client machine.
To stream images from the non-public file system of the server machine to the HTTP response, you need to create a servlet which does the simple task: read an InputStream from the file and write it to OutputStream of the response. You can find here an example: [http://balusc.blogspot.com/2007/04/imageservlet.html].

Similar Messages

  • Is it possible to get images automatically into text captions while simulation recording?

    Is it possible to get images automatically into text captions while simulation recording?

    I want that will be like described below (as it works in another software for captioning):

  • In App Store I'm blocked on the window of a certain application, not possible to get out of it

    In App Store I'm blocked on the window of a certain application, not possible to get out of it

    Try closing the App Store app via the iPad's multitasking bar and see if it works ok when you re-open it :
    iOS 7 : double-click the home button to open the taskbar, and then swipe or drag the App Store app's screen from there up and off the top of the screen to close it, and click the home button to close the taskbar.
    iOS 6 and below : from the home screen (i.e. not with the App Store 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the App Store app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't fix it then you could try a soft-reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Hi friends, I'm having troubles with my Ipad 2. I was working with it and suddenly the screen distorted. Now it is not possible to get it back to work properly. In fact, the screen is now black and nothing I have done makes the Ipad works again. Thanks

    Hi friends, I'm having troubles with my Ipad 2. I was working with it and suddenly the screen distorted. Now it is not possible to get it back to work properly. In fact, the screen is now black and nothing I have done makes the Ipad works again. Please Help. Thanks in advance.

    I think you should make an Genius Appointment.
    Genius Appointment
    http://www.apple.com/retail/geniusbar/

  • Not able to get image width after uploading image

    hi
    I am working on uploading image. Once the image is uploaded I need to know image width and height. Right now I am listening to "complete" event but it seems image is still not loaded when the complete event is raised as it returns image width as zero. This is very urgent and imp for me, Please let me know how can I get the wridth and height of image once it is uploaded on remote server
    <mx:VBox width="100%" height="100%">
                <mx:Label text="Image" />
                <mx:HBox width="100%" height="10%">
                    <mx:TextInput id="txt_imgname" width="321"/>
                    <mx:Button label="Browse"  click="bn_Browse_Click()"/>
                </mx:HBox>
            <mx:Canvas width="400"  height="264" backgroundColor="#000000" borderStyle="solid" cornerRadius="12" borderThickness="3" borderColor="#222F92">
                <mx:ProgressBar id="progressBar"  indeterminate="true" visible="false" height="1%"  />
                <mx:Image id="img" complete="{imageLoadListener(event)}" />
            </mx:Canvas>
            <mx:HBox width="100%" height="10%" horizontalAlign="right" verticalAlign="middle">
                <mx:Button label="OK" id="okbutton" click="bn_ok_click()" />
                <mx:Button label="Cancel" click="bn_cancel_click()" />
            </mx:HBox>
    private function bn_Browse_Click():void
                CreateFileReference();
                 fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData);
                 FileBrowse();
            private function FileBrowse():void
                try
                    var success:Boolean = fileReference.browse(allTypes);
                catch (error:Error)
                    Alert.show("Unable to browse for files.");
            private function CreateFileReference():void
                 var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
                 allTypes = new Array(imageTypes);
                 fileReference = new FileReference();
                 fileReference.addEventListener(Event.SELECT, selectHandler);            
                 fileReference.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);
             private function selectHandler(event:Event):void
                 var request:URLRequest = new URLRequest("http://"+TestLoginIntegration.GetServerAddress()+"/FileUpload/Default.aspx");
                try
                     request.contentType = "application/octet-stream";
                     request.method = "POST";
                   fileReference.upload(request,fileReference.name,false);  
                catch (error:Error)
                    Alert.show("Unable to upload file." + error.message);
             private function fileRef_progress(evt:ProgressEvent):void
                        img.source = "";
                    progressBar.visible = true;
            private function onUploadCompleteData (event : DataEvent) : void
                 var filePath:String = event.data;
                 img.source = filePath;
                 progressBar.visible = false;
                 txt_imgname.text = GetFileNameFromPath(filePath);
            private function imageLoadListener(e:Event):void{
               Alert.show(e.currentTarget.width);
    private function GetFileNameFromPath(filepath:String):String
                if(filepath == null || filepath == "")
                    return null;
                var name:String = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length);
                return name;

    Read this older post
    http://forums.adobe.com/message/1900768#1900768

  • Not able to get Image dimensions

    I am using this code to get the java.awt.Image object
    Image inImage = Jimi.getImage(inputStream, Jimi.SYNCHRONOUS);
    I am using Jimi because I am running my code on jdk 1.3 and cannot use JAI.
    For some images, when I do
    inImage.getHeight(null);
    I get -1 returned, but I want to get the image height because I need it to properly resize my image. Can anybody tell me why I am not getting the Image height with this code or is there some other way to get the image height ?
    Thanks in Advance
    Varun

    I don't know much about older versions of Java, like 1.3 and Jimi, but are you permitted to use MediaTracker:
    http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MediaTracker.htmlWhen methods getHeight/getWidth return -1 it's a signal that the image's data
    hasn't been loaded yet. Check out the code to do that on the above API page.

  • Not possible to get rid of Welcome Screen

    In 309 we wish to get rid of the Welcome Screen and go straight to the login screen. In 307 we did this by making the Welcome Screen not accessible to public users. If we try doing that in 309 the Sign On Screen comes up fine, but once the user has logged on it takes them to the Welcome Screen.
    I have tried setting the default homepage of the public user to something else but this then takes all users to this page even though their home page is set to something else. This happens on a fresh install of 309.
    This has been preventing us from upgrading from 307, we have been trying since 308 came out. I have seen other posts regarding the same issue (some from ourselves) but no-one has come up with a solution.
    Oracle Support have reproduced this, and it is logged as bug 1953926, so if anyone else is getting this problem please raise with support that you are getting it and hopefully we will get a response.
    If anyone on the Portal Development side could look at this I would appreciate it (I have this issue logged as tar 48199.999)
    Cheers,
    Patrick

    You can do it by putting login portlet provided by Oracle Portal
    on your welcome page and customize the welcome page. The single-
    sign on login page will never come up after you login from
    welcome page. I am not sure if it still works with customized
    login portlet.
    DD

  • Not possible to get software from Apple support

    I am trying to fix my Shuffle, however i cannot get the driver from Apple support.
    the website states "your software will be automatically downloaded" and then remains silent as a civil servant.
    This is no way to start friday.

    I had the same problem with IE. My solution was downloading Firefox and then it worked just fine.
    (Firefox is better anyway. Grinners.)

  • In posts of this forum is not possible use embedded images. Why?

    Subj...

    Hi,
    according to my information it is a security percaution to avoid hacks into OTN
    Frank
    Edited by: Frank Nimphius on Nov 26, 2009 8:34 AM

  • NOt able to get text value for 0calmonth in the query

    hi,
    I am not able to get the test for the calmonth in the selection screen of the Query.
    i.e If the user enter the value 01/2010 as input in the selection screen. I am not able to get its text Janurary 2010 displayed in the selection screen of the query.
    please let me know what could be the reason for this.
    regards,
    Mahesh

    Hi Mahesh,
    I regret to inform you there is no option to display the month text.
    The system works as designed. The "Key and text" option for the      
    infoObject is for display the technical name and the description.                                                                               
    I found a customer on SDN which the same doubt and the answer for your
    question. Please, check the link below:                                                                               
    0calday text variable        
    Best Regards,
    Des

  • Not able to get text id

    Hi Experts,
                     we have created text entry in va01 header text, so how can i pick the text since i m not able to get the text id.
    Regards
    sumit

    Hi,
    Use this FM READ_TEXT' and pass the so no, language and id as shown below, for example in me23n --> enter po no  --- click text tab ---. click header text there. In the area rightside to header text. click on that area --- then goto goto in menu ---> click header --> there u will find text id and text object there  and pass them to the FM along with ur sono.
    CONCATENATE i_ekpo-ebeln  i_ekpo-ebelp  INTO str.
          CALL FUNCTION 'READ_TEXT'
            EXPORTING
              id                      = 'F01'
              language                = sy-langu
              name                    = str
              object                  = 'EKPO'
            TABLES
         lines                   = item_i_xtline
            EXCEPTIONS
              id                      = 1
              language                = 2
              name                    = 3
              not_found               = 4
              object                  = 5
              reference_check         = 6
              wrong_access_to_archive = 7
              OTHERS                  = 8.
    Regards,
    Kiran.

  • How to get images dynamically from database without file paths in the table field

    I have a MS-Access database. I am working with ASP.NET. In the database there is product table in which I have "CodeNo" as a field which is a text field, and the product codes like "SM-R-2035". I also have another field "Image" which is also a text field and which have a file path in it corresponding to the particular product Image (e.g. Images\Products\SM-R-2035.jpg). So far every thing is ok. I have to update this site very frequently and lots of images are added each and every time. Its a tedious work to type the paths and file name every time and it also take a lot of time.
    What I am asking is : Is it possible to get images from a specific folder at runtime which is referenced by the "code no" itself and not the file path from the database. (Say at run time the "code no" is referenced from the database and the corresponding image is loaded dynamically from the specified folder). In other word I want to avoid the tedious work of typing.
    Can any one help with this issue. Any other simple suggestions are welcome.

    All you need to do is simple concatenation to obtain the path for the image file.  You didn't mention whether you are using VB.Net, C# or some other language to do your coding.
    If the code in your database is SM-R-2035, the file name is SM-R-2035.jpg and the path to the images foilder is Images\Products\SM-R-2035.jpg, Conceptually here is what you need to do:
    dim code_var
    dim path_var
    code_var = the code you obtain from your relevant field in the database
    path_var = "Images\Products\" & code_var & ".jpg"
    Now path_var is what you would call to obtain the image from your images folder.

  • Is it possible to insert images in Adobe 9 Standard?

    It appears that it is not possible to insert images in Adobe 9 Standard.  There is no TouchUp Object Tool in the Advanced Editing Toolbar in the standard version.  Only a TouchUp Text Tool.  Is this not a basic function being able to add or change an image in a document?  The tutorials all show this as a capability but they are also demonstrating in the Pro version of Acrobat.  Is there a work around or have I been suckered into buying a product that doesn't quite meet my needs? 

    The Touch-Up Object tool is not available in Standard.
    Adobe Acrobat is not meant to be a word processing program; it is meant to be a cross-platform method for document exchange. Changes are best made in the source program. While the answer to your question would not have been obvious from this list, it is a good reference for the difference between Acrobat products: http://www.adobe.com/products/acrobat/matrix.html .
    If for some reason it is not possible to edit the source file and create the pdf again, you can insert your image as a form button and then flatten it. A lot more work, but post if you want help with this.
    --For other folks reading this thread, Adobe offers trials of its programs. Consider testing before buying.

  • Posting with transaction type 160 is not possible at MR8M

    MODERATOR:  Do not post (or request) email address or links to copyrighted or confidential information on these forums.  If you do, the thread will be LOCKED and all points UNASSIGNED.  If you have some information, please consider posting it to the [Wiki|https://wiki.sdn.sap.com/wiki/display/ERPFI/Home] rather than sharing via email.  Thank you for your assistance.
    Hi All,
    We raised  a PO w.r.t CWIP asset and posted GRN (MIGO - Transaction typr:100) and Invoice (MIRO).
    Here, Invoice posted wrongly, So we are trying to reverse the invoice with MR8M (which is posted thru MIRO).
    But system populating one message as per the following:
    Posting with transaction type 160 is not possible here, see long text
    Message no. AAPO 177
    Diagnosis:
    Transaction type 160 has a depreciation limitation, although posting is not mandatory in all of the depreciation areas entered However, it is not possible to select depreciation areas in the current transactions.
    Procedure:
    Check the specification of transaction type 160 or use transaction MR8M to enter the transaction
    Please help
    Sairavi
    kumarfi9gmailcom

    Welcome to the forum.
    As a newbie you should understand the forum rules where you are not suppose to post any basic or repeated question.  To avoid this, you should make a search here
    [Forum Search|http://forums.sdn.sap.com/search!default.jspa?objID=f327]
    Type the same error text in Search Terms so that you will find the solution.
    thanks
    G. Lakshmipathi

  • Is it possible to get airplay mirror capability on Mac OS X Lion 10.7.5?

    Is it possible to get the Airplay mirroring capability on Mac OS X Lion 10.7.5? If not what are the best options for obtaining the mirroring feature?

    Hello! It's not possible to get Airplay Mirroring. There are 3rd-party options, the most well-know being Airparrot. http://www.airsquirrels.com/airparrot/

Maybe you are looking for